Example #1
0
        public static Result DeleteToaCapCuu(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        ToaCapCuu toaCapCuu = db.ToaCapCuus.SingleOrDefault <ToaCapCuu>(tt => tt.ToaCapCuuGUID.ToString() == key);
                        if (toaCapCuu != null)
                        {
                            toaCapCuu.DeletedDate = DateTime.Now;
                            toaCapCuu.DeletedBy   = Guid.Parse(Global.UserGUID);
                            toaCapCuu.Status      = (byte)Status.Deactived;

                            string basSiKeToa = string.Empty;
                            if (toaCapCuu.DocStaff != null)
                            {
                                basSiKeToa = toaCapCuu.DocStaff.Contact.FullName;
                            }

                            desc += string.Format("- GUID: '{0}', Mã toa cấp cứu: '{1}', Ngày kê toa: '{2}', Bác sĩ kê toa: '{3}', Bệnh nhân: '{4}', Ghi chú: '{5}'\n",
                                                  toaCapCuu.ToaCapCuuGUID.ToString(), toaCapCuu.MaToaCapCuu, toaCapCuu.NgayKeToa.ToString("dd/MM/yyyy HH:mm:ss"), basSiKeToa,
                                                  toaCapCuu.TenBenhNhan, toaCapCuu.Note);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin toa cấp cứu";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #2
0
        public static Result ChuyenBenhAn(string patientGUID, List <DataRow> rows)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    foreach (DataRow row in rows)
                    {
                        string  chiDinhGUID = row["ChiDinhGUID"].ToString();
                        ChiDinh chiDinh     = (from s in db.ChiDinhs
                                               where s.ChiDinhGUID.ToString() == chiDinhGUID
                                               select s).FirstOrDefault();

                        if (chiDinh == null)
                        {
                            continue;
                        }

                        //Tracking
                        string desc = string.Format("- ChiDinhGUID: '{0}': PatientGUID: '{1}' ==> '{2}' (ChiDinh)",
                                                    chiDinhGUID, chiDinh.BenhNhanGUID.ToString(), patientGUID);

                        chiDinh.BenhNhanGUID = Guid.Parse(patientGUID);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Edit;
                        tk.Action       = "Chuyển bệnh án";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);
                    }

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #3
0
        public static Result InsertCompany(Company com, List <string> addedMembers, List <string> deletedMembers)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;

                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (com.CompanyGUID == null || com.CompanyGUID == Guid.Empty)
                    {
                        com.CompanyGUID = Guid.NewGuid();
                        db.Companies.InsertOnSubmit(com);
                        db.SubmitChanges();

                        desc += string.Format("- Công ty: GUID: '{0}', Mã cty: '{1}', Tên cty: '{2}', Địa chỉ: '{3}', Điện thoại: '{4}', Fax: '{5}', Website: '{6}', Mã số thuế: '{7}'\n",
                                              com.CompanyGUID.ToString(), com.MaCty, com.TenCty, com.DiaChi, com.Dienthoai, com.Fax, com.Website, com.MaSoThue);

                        //Members
                        if (addedMembers != null && addedMembers.Count > 0)
                        {
                            desc += "- Danh sách nhân viên:\n";
                            foreach (string key in addedMembers)
                            {
                                CompanyMember m = db.CompanyMembers.SingleOrDefault <CompanyMember>(mm => mm.PatientGUID.ToString() == key &&
                                                                                                    mm.CompanyGUID.ToString() == com.CompanyGUID.ToString());
                                if (m == null)
                                {
                                    m = new CompanyMember();
                                    m.CompanyMemberGUID = Guid.NewGuid();
                                    m.CompanyGUID       = com.CompanyGUID;
                                    m.PatientGUID       = Guid.Parse(key);
                                    m.CreatedDate       = DateTime.Now;
                                    m.CreatedBy         = Guid.Parse(Global.UserGUID);
                                    m.Status            = (byte)Status.Actived;
                                    db.CompanyMembers.InsertOnSubmit(m);
                                    db.SubmitChanges();
                                }
                                else
                                {
                                    m.Status      = (byte)Status.Actived;
                                    m.UpdatedDate = DateTime.Now;
                                    m.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                }

                                desc += string.Format("  + GUID: '{0}', Nhân viên: '{1}'\n", m.CompanyMemberGUID.ToString(), m.Patient.Contact.FullName);
                            }

                            db.SubmitChanges();
                        }

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin công ty";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);
                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        Company company = db.Companies.SingleOrDefault <Company>(c => c.CompanyGUID.ToString() == com.CompanyGUID.ToString());
                        if (company != null)
                        {
                            company.MaCty       = com.MaCty;
                            company.MaSoThue    = com.MaSoThue;
                            company.TenCty      = com.TenCty;
                            company.DiaChi      = com.DiaChi;
                            company.Dienthoai   = com.Dienthoai;
                            company.Fax         = com.Fax;
                            company.Website     = com.Website;
                            company.CreatedDate = com.CreatedDate;
                            company.CreatedBy   = com.CreatedBy;
                            company.UpdatedDate = com.UpdatedDate;
                            company.UpdatedBy   = com.UpdatedBy;
                            company.DeletedDate = com.DeletedDate;
                            company.DeletedBy   = com.DeletedBy;
                            company.Status      = com.Status;

                            desc += string.Format("- Công ty: GUID: '{0}', Mã cty: '{1}', Tên cty: '{2}', Địa chỉ: '{3}', Điện thoại: '{4}', Fax: '{5}', Website: '{6}', Mã số thuế: '{7}'\n",
                                                  company.CompanyGUID.ToString(), company.MaCty, company.TenCty, company.DiaChi, company.Dienthoai, company.Fax, company.Website, company.MaSoThue);

                            //Members
                            if (deletedMembers != null && deletedMembers.Count > 0)
                            {
                                desc += "- Danh sách nhân viên được xóa:\n";
                                foreach (string key in deletedMembers)
                                {
                                    CompanyMember m = db.CompanyMembers.SingleOrDefault <CompanyMember>(mm => mm.PatientGUID.ToString() == key &&
                                                                                                        mm.CompanyGUID.ToString() == com.CompanyGUID.ToString());
                                    if (m != null)
                                    {
                                        m.Status      = (byte)Status.Deactived;
                                        m.DeletedDate = DateTime.Now;
                                        m.DeletedBy   = Guid.Parse(Global.UserGUID);

                                        desc += string.Format("  + GUID: '{0}', Nhân viên: '{1}'\n", m.CompanyMemberGUID.ToString(), m.Patient.Contact.FullName);
                                    }
                                }

                                db.SubmitChanges();
                            }

                            if (addedMembers != null && addedMembers.Count > 0)
                            {
                                string addedStr = string.Empty;
                                bool   isAdd    = false;

                                foreach (string key in addedMembers)
                                {
                                    CompanyMember m = db.CompanyMembers.SingleOrDefault <CompanyMember>(mm => mm.PatientGUID.ToString() == key &&
                                                                                                        mm.CompanyGUID.ToString() == com.CompanyGUID.ToString());
                                    if (m == null)
                                    {
                                        m = new CompanyMember();
                                        m.CompanyMemberGUID = Guid.NewGuid();
                                        m.CompanyGUID       = com.CompanyGUID;
                                        m.PatientGUID       = Guid.Parse(key);
                                        m.CreatedDate       = DateTime.Now;
                                        m.CreatedBy         = Guid.Parse(Global.UserGUID);
                                        m.Status            = (byte)Status.Actived;
                                        db.CompanyMembers.InsertOnSubmit(m);
                                        db.SubmitChanges();

                                        addedStr += string.Format("  + GUID: '{0}', Nhân viên: '{1}'\n", m.CompanyMemberGUID.ToString(), m.Patient.Contact.FullName);
                                        isAdd     = true;
                                    }
                                    else
                                    {
                                        if (m.Status == (byte)Status.Deactived)
                                        {
                                            addedStr += string.Format("  + GUID: '{0}', Nhân viên: '{1}'\n", m.CompanyMemberGUID.ToString(), m.Patient.Contact.FullName);
                                            isAdd     = true;
                                        }

                                        m.Status      = (byte)Status.Actived;
                                        m.UpdatedDate = DateTime.Now;
                                        m.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                    }
                                }

                                db.SubmitChanges();

                                if (isAdd)
                                {
                                    addedStr = "- Danh sách nhân viên được thêm:\n" + addedStr;
                                }
                                desc += addedStr;
                            }

                            //Tracking
                            desc = desc.Substring(0, desc.Length - 1);
                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin công ty";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);
                            db.SubmitChanges();
                        }
                    }
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #4
0
        public static Result DeleteDichVuLamThem(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        DichVuLamThem s = db.DichVuLamThems.SingleOrDefault <DichVuLamThem>(ss => ss.DichVuLamThemGUID.ToString() == key);
                        if (s != null)
                        {
                            s.DeletedDate = DateTime.Now;
                            s.DeletedBy   = Guid.Parse(Global.UserGUID);
                            s.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Mã dịch vụ: '{1}', Tên dịch vụ: '{2}', Tên tiếng anh: '{3}', Giá: '{4}', Giảm: '{5}', Ngày sử dụng: '{6}', Đã thu tiền: '{7}'\n",
                                                  s.DichVuLamThemGUID.ToString(), s.Service.Code, s.Service.Name, s.Service.EnglishName, s.Price, s.Discount, s.ActiveDate.ToString("dd/MM/yyyy HH:mm:ss"), s.DaThuTien);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa dịch vụ làm thêm";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.Price;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #5
0
        public static Result InsertChiDinh(ChiDinh chiDinh, List <ChiTietChiDinh> addedList, List <string> deletedList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;

                //Insert
                if (chiDinh.ChiDinhGUID == null || chiDinh.ChiDinhGUID == Guid.Empty)
                {
                    chiDinh.ChiDinhGUID = Guid.NewGuid();
                    db.ChiDinhs.InsertOnSubmit(chiDinh);
                    db.SubmitChanges();

                    desc += string.Format("- Chỉ định: GUID: '{0}', Mã chỉ định: '{1}', Ngày chỉ định: '{2}', Bác sĩ chỉ định: '{3}', Bệnh nhân: '{4}'\n",
                                          chiDinh.ChiDinhGUID.ToString(), chiDinh.MaChiDinh, chiDinh.NgayChiDinh.ToString("dd/MM/yyyy HH:mm:ss"),
                                          chiDinh.DocStaff.Contact.FullName, chiDinh.Patient.Contact.FullName);

                    //Add chi tiet
                    if (addedList != null && addedList.Count > 0)
                    {
                        desc += "- Chi tiết chỉ định được thêm:\n";

                        foreach (ChiTietChiDinh ctcd in addedList)
                        {
                            ctcd.ChiTietChiDinhGUID = Guid.NewGuid();
                            ctcd.ChiDinhGUID        = chiDinh.ChiDinhGUID;
                            db.ChiTietChiDinhs.InsertOnSubmit(ctcd);
                            db.SubmitChanges();

                            desc += string.Format("  + GUID: '{0}', Dịch vụ: '{1}'\n", ctcd.ChiTietChiDinhGUID.ToString(), ctcd.Service.Name);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Add;
                    tk.Action       = "Thêm thông tin chỉ định";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);
                    db.SubmitChanges();
                }
                else //Update
                {
                    ChiDinh cd = db.ChiDinhs.SingleOrDefault <ChiDinh>(c => c.ChiDinhGUID.ToString() == chiDinh.ChiDinhGUID.ToString());
                    if (cd != null)
                    {
                        cd.MaChiDinh        = chiDinh.MaChiDinh;
                        cd.NgayChiDinh      = chiDinh.NgayChiDinh;
                        cd.BacSiChiDinhGUID = chiDinh.BacSiChiDinhGUID;
                        cd.BenhNhanGUID     = chiDinh.BenhNhanGUID;
                        cd.CreatedDate      = chiDinh.CreatedDate;
                        cd.CreatedBy        = chiDinh.CreatedBy;
                        cd.UpdatedDate      = chiDinh.UpdatedDate;
                        cd.UpdatedBy        = chiDinh.UpdatedBy;
                        cd.DeletedDate      = chiDinh.DeletedDate;
                        cd.DeletedBy        = chiDinh.DeletedBy;
                        cd.Status           = chiDinh.Status;
                        db.SubmitChanges();

                        desc += string.Format("- Chỉ định: GUID: '{0}', Mã chỉ định: '{1}', Ngày chỉ định: '{2}', Bác sĩ chỉ định: '{3}', Bệnh nhân: '{4}'\n",
                                              cd.ChiDinhGUID.ToString(), cd.MaChiDinh, cd.NgayChiDinh.ToString("dd/MM/yyyy HH:mm:ss"),
                                              cd.DocStaff.Contact.FullName, cd.Patient.Contact.FullName);

                        //Delete chi tiet
                        if (deletedList != null && deletedList.Count > 0)
                        {
                            desc += "- Chi tiết chỉ định được xóa:\n";
                            foreach (string key in deletedList)
                            {
                                ChiTietChiDinh ctcd = db.ChiTietChiDinhs.SingleOrDefault <ChiTietChiDinh>(c => c.ChiTietChiDinhGUID.ToString() == key);
                                if (ctcd != null)
                                {
                                    ctcd.DeletedDate = DateTime.Now;
                                    ctcd.DeletedBy   = Guid.Parse(Global.UserGUID);
                                    ctcd.Status      = (byte)Status.Deactived;

                                    desc += string.Format("  + GUID: '{0}', Dịch vụ: '{1}'\n", ctcd.ChiTietChiDinhGUID.ToString(), ctcd.Service.Name);
                                }
                            }

                            db.SubmitChanges();
                        }

                        //Add chi tiet
                        if (addedList != null && addedList.Count > 0)
                        {
                            string addedStr = string.Empty;
                            bool   isAdd    = false;
                            foreach (ChiTietChiDinh ctcd in addedList)
                            {
                                ChiTietChiDinh ct = db.ChiTietChiDinhs.SingleOrDefault <ChiTietChiDinh>(c => c.ServiceGUID == ctcd.ServiceGUID &&
                                                                                                        c.ChiDinhGUID == cd.ChiDinhGUID);
                                if (ct == null)
                                {
                                    ctcd.ChiTietChiDinhGUID = Guid.NewGuid();
                                    ctcd.ChiDinhGUID        = cd.ChiDinhGUID;
                                    ctcd.CreatedDate        = DateTime.Now;
                                    ctcd.CreatedBy          = Guid.Parse(Global.UserGUID);
                                    db.ChiTietChiDinhs.InsertOnSubmit(ctcd);
                                    db.SubmitChanges();

                                    addedStr += string.Format("  + GUID: '{0}', Dịch vụ: '{1}'\n", ctcd.ChiTietChiDinhGUID.ToString(), ctcd.Service.Name);
                                    isAdd     = true;
                                }
                                else
                                {
                                    if (ct.Status == (byte)Status.Deactived)
                                    {
                                        addedStr += string.Format("  + GUID: '{0}', Dịch vụ: '{1}'\n", ct.ChiTietChiDinhGUID.ToString(), ct.Service.Name);
                                        isAdd     = true;
                                    }

                                    ct.UpdatedDate = DateTime.Now;
                                    ct.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                    ct.Status      = (byte)Status.Actived;
                                }
                            }

                            db.SubmitChanges();

                            if (isAdd)
                            {
                                addedStr = "- Chi tiết chỉ định được thêm:\n" + addedStr;
                            }
                            desc += addedStr;
                        }

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Edit;
                        tk.Action       = "Sửa thông tin chỉ định";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);
                        db.SubmitChanges();
                    }
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #6
0
        public static Result DeleteKetQuaSieuAm(List <String> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        KetQuaSieuAm kqsa = db.KetQuaSieuAms.SingleOrDefault <KetQuaSieuAm>(k => k.KetQuaSieuAmGUID.ToString() == key);
                        if (kqsa != null)
                        {
                            kqsa.DeletedDate = DateTime.Now;
                            kqsa.DeletedBy   = Guid.Parse(Global.UserGUID);
                            kqsa.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Ngày siêu âm: '{1}', Bệnh nhân: '{2}', Bác sĩ siêu âm: '{3}', Bác sĩ chỉ định: '{4}', Loại siêu âm: '{5}'\n",
                                                  kqsa.KetQuaSieuAmGUID.ToString(), kqsa.NgaySieuAm.Value.ToString("dd/MM/yyyy HH:mm:ss"), kqsa.Patient.Contact.FullName,
                                                  kqsa.BacSiSieuAmGUID.ToString(), kqsa.BacSiChiDinhGUID.ToString(), kqsa.LoaiSieuAm.TenSieuAm);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa kết quả siêu âm";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #7
0
        public static Result DeleteKetQuaLamSang(List <String> ketQuaLamSangKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in ketQuaLamSangKeys)
                    {
                        KetQuaLamSang kqls = db.KetQuaLamSangs.SingleOrDefault <KetQuaLamSang>(k => k.KetQuaLamSangGUID.ToString() == key);
                        if (kqls != null)
                        {
                            kqls.DeletedDate = DateTime.Now;
                            kqls.DeletedBy   = Guid.Parse(Global.UserGUID);
                            kqls.Status      = (byte)Status.Deactived;

                            string ketQua = string.Empty;
                            if (kqls.Normal)
                            {
                                ketQua += "Bình thường, ";
                            }
                            if (kqls.Abnormal)
                            {
                                ketQua += "Bất thường, ";
                            }

                            if (ketQua != string.Empty)
                            {
                                ketQua = ketQua.Substring(0, ketQua.Length - 2);
                            }


                            if (kqls.CoQuan != (byte)CoQuan.KhamPhuKhoa)
                            {
                                desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Cơ quan: '{3}', Kết quả: '{4}', Nhận xét: '{5}'\n",
                                                      kqls.KetQuaLamSangGUID.ToString(), kqls.Patient.Contact.FullName, kqls.DocStaff.Contact.FullName,
                                                      Utility.ParseCoQuanEnumToName((CoQuan)kqls.CoQuan), ketQua, kqls.Note);
                            }
                            else
                            {
                                if (kqls.NgayKinhChot.HasValue)
                                {
                                    desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Cơ quan: '{3}', PARA: '{4}', Ngày kinh chót: '{5}', Ghi chú: '{6}', Kết quả khám phụ khoa: '{7}', Soi tươi huyết trắng: '{8}', Kết quả Pap: '{9}'\n",
                                                          kqls.KetQuaLamSangGUID.ToString(), kqls.Patient.Contact.FullName, kqls.DocStaff.Contact.FullName,
                                                          Utility.ParseCoQuanEnumToName((CoQuan)kqls.CoQuan), kqls.PARA, kqls.NgayKinhChot.Value.ToString("dd/MM/yyyy"),
                                                          kqls.PhuKhoaNote, kqls.Note, kqls.SoiTuoiHuyetTrang, ketQua);
                                }
                                else
                                {
                                    desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Cơ quan: '{3}', PARA: '{4}', Ghi chú: '{5}', Kết quả khám phụ khoa: '{6}', Soi tươi huyết trắng: '{7}', Kết quả Pap: '{8}'\n",
                                                          kqls.KetQuaLamSangGUID.ToString(), kqls.Patient.Contact.FullName, kqls.DocStaff.Contact.FullName,
                                                          Utility.ParseCoQuanEnumToName((CoQuan)kqls.CoQuan), kqls.PARA, kqls.PhuKhoaNote, kqls.Note, kqls.SoiTuoiHuyetTrang, ketQua);
                                }
                            }
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin khám lâm sàng";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #8
0
        public static Result DeletePhieuThuThuoc(List <string> phieuThuThuocKeys, List <string> noteList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    DateTime dt    = DateTime.Now;
                    string   desc  = string.Empty;
                    int      index = 0;
                    foreach (string key in phieuThuThuocKeys)
                    {
                        PhieuThuThuoc ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.PhieuThuThuocGUID.ToString() == key);
                        if (ptthuoc != null)
                        {
                            Status status = (Status)ptthuoc.Status;
                            ptthuoc.DeletedDate = DateTime.Now;
                            ptthuoc.DeletedBy   = Guid.Parse(Global.UserGUID);
                            ptthuoc.Status      = (byte)Status.Deactived;
                            ptthuoc.Notes       = noteList[index];

                            if (status == (byte)Status.Actived)
                            {
                                //Update So luong Lo thuoc
                                var ctptts = ptthuoc.ChiTietPhieuThuThuocs;
                                foreach (var ctptt in ctptts)
                                {
                                    int soLuong = Convert.ToInt32(ctptt.SoLuong);

                                    var loThuocList = from l in db.LoThuocs
                                                      where l.Status == (byte)Status.Actived &&
                                                      l.ThuocGUID == ctptt.ThuocGUID &&
                                                      new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) > dt &&
                                                      l.SoLuongXuat > 0
                                                      orderby new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) ascending, l.CreatedDate ascending
                                    select l;

                                    if (loThuocList != null)
                                    {
                                        foreach (var lt in loThuocList)
                                        {
                                            if (soLuong > 0)
                                            {
                                                if (lt.SoLuongXuat >= soLuong)
                                                {
                                                    lt.SoLuongXuat -= soLuong;
                                                    soLuong         = 0;
                                                    db.SubmitChanges();
                                                    break;
                                                }
                                                else
                                                {
                                                    soLuong       -= lt.SoLuongXuat;
                                                    lt.SoLuongXuat = 0;
                                                    db.SubmitChanges();
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Utility.WriteToTraceLog(string.Format("Không tồn tại lô thuốc: '{0}', Mã phiếu thu: '{1}'",
                                                                              ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc));
                                    }
                                }
                            }

                            string maToaThuoc = string.Empty;
                            if (ptthuoc.ToaThuocGUID.Value != Guid.Empty)
                            {
                                maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc;
                            }

                            desc += string.Format("- GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Lý do giảm: '{9}', Hình thức thanh toán: '{10}'\n",
                                                  ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, noteList[index], !ptthuoc.ChuaThuTien, ptthuoc.LyDoGiam, ptthuoc.HinhThucThanhToan);
                        }

                        index++;
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin phiếu thu thuốc";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.Price;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #9
0
        public static Result InsertPhieuThuThuoc(PhieuThuThuoc ptthuoc, List <ChiTietPhieuThuThuoc> addedList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ptthuoc.PhieuThuThuocGUID == null || ptthuoc.PhieuThuThuocGUID == Guid.Empty)
                    {
                        ptthuoc.PhieuThuThuocGUID = Guid.NewGuid();
                        db.PhieuThuThuocs.InsertOnSubmit(ptthuoc);
                        db.SubmitChanges();

                        string maToaThuoc = string.Empty;
                        if (ptthuoc.ToaThuocGUID.Value != Guid.Empty)
                        {
                            maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc;
                        }

                        desc += string.Format("- Phiếu thu thuốc: GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Lý do giảm: '{9}', Hình thức thanh toán: '{10}'\n",
                                              ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                              ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, ptthuoc.Notes, !ptthuoc.ChuaThuTien, ptthuoc.LyDoGiam, ptthuoc.HinhThucThanhToan);

                        desc += "- Chi tiết phiếu thu thuốc được thêm:\n";

                        //Chi tiet phieu thu
                        DateTime dt = DateTime.Now;
                        foreach (ChiTietPhieuThuThuoc ctptt in addedList)
                        {
                            ctptt.PhieuThuThuocGUID        = ptthuoc.PhieuThuThuocGUID;
                            ctptt.ChiTietPhieuThuThuocGUID = Guid.NewGuid();

                            int soLuong = Convert.ToInt32(ctptt.SoLuong);
                            if (soLuong <= 0)
                            {
                                Utility.WriteToTraceLog(string.Format("Số lượng: '{0}', Mã thuốc: '{1}', Mã phiếu thu: '{2}'",
                                                                      soLuong, ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc));
                            }

                            var loThuocList = from l in db.LoThuocs
                                              where l.Status == (byte)Status.Actived &&
                                              l.ThuocGUID == ctptt.ThuocGUID &&
                                              new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) > dt &&
                                              l.SoLuongNhap * l.SoLuongQuiDoi - l.SoLuongXuat > 0
                                              orderby new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) ascending, l.CreatedDate ascending
                            select l;

                            double giaNhapTB = 0;
                            if (loThuocList != null)
                            {
                                double tongGiaNhap = 0;
                                int    count       = 0;
                                foreach (var lt in loThuocList)
                                {
                                    if (soLuong > 0)
                                    {
                                        int soLuongTon = lt.SoLuongNhap * lt.SoLuongQuiDoi - lt.SoLuongXuat;
                                        if (soLuongTon >= soLuong)
                                        {
                                            lt.SoLuongXuat += soLuong;
                                            tongGiaNhap    += (soLuong * lt.GiaNhapQuiDoi);
                                            count          += soLuong;
                                            soLuong         = 0;
                                            db.SubmitChanges();
                                            break;
                                        }
                                        else
                                        {
                                            lt.SoLuongXuat += soLuongTon;
                                            soLuong        -= soLuongTon;
                                            tongGiaNhap    += (soLuongTon * lt.GiaNhapQuiDoi);
                                            count          += soLuongTon;
                                            db.SubmitChanges();
                                        }
                                    }
                                }

                                giaNhapTB = Math.Round(tongGiaNhap / count, 0);
                            }
                            else
                            {
                                Utility.WriteToTraceLog(string.Format("Không tồn tại lô thuốc: '{0}', Mã phiếu thu: '{1}'",
                                                                      ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc));
                            }

                            ctptt.DonGiaNhap = giaNhapTB;
                            db.ChiTietPhieuThuThuocs.InsertOnSubmit(ctptt);
                            db.SubmitChanges();

                            desc += string.Format("  + GUID: '{0}', Thuốc: '{1}', Đơn giá: '{2}', Số lượng: '{3}', Giảm: '{4}', Thành tiền: '{5}', Đơn giá nhập: '{6}'\n",
                                                  ctptt.ChiTietPhieuThuThuocGUID.ToString(), ctptt.Thuoc.TenThuoc, ctptt.DonGia, ctptt.SoLuong, ctptt.Giam, ctptt.ThanhTien, ctptt.DonGiaNhap);
                        }

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin phiếu thu thuốc";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #10
0
        public static Result DeleteLoiKhuyen(List <String> loiKhuyenKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in loiKhuyenKeys)
                    {
                        LoiKhuyen loiKhuyen = db.LoiKhuyens.SingleOrDefault <LoiKhuyen>(l => l.LoiKhuyenGUID.ToString() == key);
                        if (loiKhuyen != null)
                        {
                            loiKhuyen.DeletedDate = DateTime.Now;
                            loiKhuyen.DeletedBy   = Guid.Parse(Global.UserGUID);
                            loiKhuyen.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Triệu chứng: '{3}', Lời khuyên: '{4}'\n",
                                                  loiKhuyen.LoiKhuyenGUID.ToString(), loiKhuyen.Patient.Contact.FullName, loiKhuyen.DocStaff.Contact.FullName,
                                                  loiKhuyen.Symptom.SymptomName, loiKhuyen.Symptom.Advice);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin lời khuyên";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #11
0
        public static Result InsertLoiKhuyen(LoiKhuyen loiKhuyen)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (loiKhuyen.LoiKhuyenGUID == null || loiKhuyen.LoiKhuyenGUID == Guid.Empty)
                    {
                        loiKhuyen.LoiKhuyenGUID = Guid.NewGuid();
                        db.LoiKhuyens.InsertOnSubmit(loiKhuyen);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Triệu chứng: '{3}', Lời khuyên: '{4}'",
                                              loiKhuyen.LoiKhuyenGUID.ToString(), loiKhuyen.Patient.Contact.FullName, loiKhuyen.DocStaff.Contact.FullName,
                                              loiKhuyen.Symptom.SymptomName, loiKhuyen.Symptom.Advice);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin lời khuyên";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        LoiKhuyen lk = db.LoiKhuyens.SingleOrDefault <LoiKhuyen>(l => l.LoiKhuyenGUID.ToString() == loiKhuyen.LoiKhuyenGUID.ToString());
                        if (lk != null)
                        {
                            lk.Ngay         = loiKhuyen.Ngay;
                            lk.PatientGUID  = loiKhuyen.PatientGUID;
                            lk.DocStaffGUID = loiKhuyen.DocStaffGUID;
                            lk.SymptomGUID  = loiKhuyen.SymptomGUID;
                            lk.Note         = loiKhuyen.Note;
                            lk.CreatedBy    = loiKhuyen.CreatedBy;
                            lk.CreatedDate  = loiKhuyen.CreatedDate;
                            lk.DeletedBy    = loiKhuyen.DeletedBy;
                            lk.DeletedDate  = loiKhuyen.DeletedDate;
                            lk.UpdatedBy    = loiKhuyen.UpdatedBy;
                            lk.UpdatedDate  = loiKhuyen.UpdatedDate;
                            lk.Status       = loiKhuyen.Status;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Bệnh nhân: '{1}', Bác sĩ: '{2}', Triệu chứng: '{3}', Lời khuyên: '{4}'",
                                                  lk.LoiKhuyenGUID.ToString(), lk.Patient.Contact.FullName, lk.DocStaff.Contact.FullName,
                                                  lk.Symptom.SymptomName, lk.Symptom.Advice);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin lời khuyên";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #12
0
        public static Result InsertGiaVonDichVu(GiaVonDichVu giaVonDichVu)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;

                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (giaVonDichVu.GiaVonDichVuGUID == null || giaVonDichVu.GiaVonDichVuGUID == Guid.Empty)
                    {
                        giaVonDichVu.GiaVonDichVuGUID = Guid.NewGuid();
                        db.GiaVonDichVus.InsertOnSubmit(giaVonDichVu);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Dịch vụ: '{1}', Giá vốn: '{2}', Ngày áp dụng: '{3}'",
                                              giaVonDichVu.GiaVonDichVuGUID.ToString(), giaVonDichVu.Service.Name, giaVonDichVu.GiaVon,
                                              giaVonDichVu.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin giá vốn dịch vụ";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        GiaVonDichVu gvdv = db.GiaVonDichVus.SingleOrDefault <GiaVonDichVu>(g => g.GiaVonDichVuGUID.ToString() == giaVonDichVu.GiaVonDichVuGUID.ToString());
                        if (gvdv != null)
                        {
                            double giaCu = gvdv.GiaVon;

                            gvdv.ServiceGUID = giaVonDichVu.ServiceGUID;
                            gvdv.GiaVon      = giaVonDichVu.GiaVon;
                            gvdv.NgayApDung  = giaVonDichVu.NgayApDung;
                            gvdv.Note        = giaVonDichVu.Note;
                            gvdv.CreatedDate = giaVonDichVu.CreatedDate;
                            gvdv.CreatedBy   = giaVonDichVu.CreatedBy;
                            gvdv.UpdatedDate = giaVonDichVu.UpdatedDate;
                            gvdv.UpdatedBy   = giaVonDichVu.UpdatedBy;
                            gvdv.DeletedDate = giaVonDichVu.DeletedDate;
                            gvdv.DeletedBy   = giaVonDichVu.DeletedBy;
                            gvdv.Status      = giaVonDichVu.Status;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Dịch vụ: '{1}', Giá vốn: cũ: '{2}' - mới: '{3}', Ngày áp dụng: '{4}'",
                                                  gvdv.GiaVonDichVuGUID.ToString(), gvdv.Service.Name, giaCu, gvdv.GiaVon, gvdv.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin giá vốn dịch vụ";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.Price;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #13
0
        public static Result DeleteGiaVonDichVu(List <string> giaVonDichVuKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in giaVonDichVuKeys)
                    {
                        GiaVonDichVu giaVon = db.GiaVonDichVus.SingleOrDefault <GiaVonDichVu>(g => g.GiaVonDichVuGUID.ToString() == key);
                        if (giaVon != null)
                        {
                            giaVon.DeletedDate = DateTime.Now;
                            giaVon.DeletedBy   = Guid.Parse(Global.UserGUID);
                            giaVon.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Dịch vụ: '{1}', Giá vốn: '{2}', Ngày áp dụng: '{3}'\n",
                                                  giaVon.GiaVonDichVuGUID.ToString(), giaVon.Service.Name, giaVon.GiaVon, giaVon.NgayApDung.ToString("dd/MM/yyyy HH:mm:ss"));
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin giá vốn dịch vụ";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.Price;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #14
0
        public static Result InsertToaCapCuu(ToaCapCuu toaCapCuu, List <ChiTietToaCapCuu> addedList, List <string> deletedKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (toaCapCuu.ToaCapCuuGUID == null || toaCapCuu.ToaCapCuuGUID == Guid.Empty)
                    {
                        toaCapCuu.ToaCapCuuGUID = Guid.NewGuid();
                        db.ToaCapCuus.InsertOnSubmit(toaCapCuu);
                        db.SubmitChanges();

                        string basSiKeToa = string.Empty;
                        if (toaCapCuu.DocStaff != null)
                        {
                            basSiKeToa = toaCapCuu.DocStaff.Contact.FullName;
                        }

                        desc += string.Format("-Toa cấp cứu GUID: '{0}', Mã toa cấp cứu: '{1}', Ngày kê toa: '{2}', Bác sĩ kê toa: '{3}', Bệnh nhân: '{4}', Ghi chú: '{5}'\n",
                                              toaCapCuu.ToaCapCuuGUID.ToString(), toaCapCuu.MaToaCapCuu, toaCapCuu.NgayKeToa.ToString("dd/MM/yyyy HH:mm:ss"), basSiKeToa,
                                              toaCapCuu.TenBenhNhan, toaCapCuu.Note);

                        if (addedList != null && addedList.Count > 0)
                        {
                            desc += "- Chi tiết toa cấp cứu được thêm:\n";

                            //Chi tiet toa cấp cứu
                            foreach (ChiTietToaCapCuu cttcc in addedList)
                            {
                                cttcc.ChiTietToaCapCuuGUID = Guid.NewGuid();
                                cttcc.ToaCapCuuGUID        = toaCapCuu.ToaCapCuuGUID;
                                db.ChiTietToaCapCuus.InsertOnSubmit(cttcc);
                                db.SubmitChanges();

                                desc += string.Format("  + GUID: '{0}', Tên cấp cứu: '{1}', Số lượng: '{2}'\n", cttcc.ChiTietToaCapCuuGUID.ToString(),
                                                      cttcc.KhoCapCuu.TenCapCuu, cttcc.SoLuong);
                            }
                        }

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin toa cấp cứu";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        ToaCapCuu tcc = db.ToaCapCuus.SingleOrDefault <ToaCapCuu>(o => o.ToaCapCuuGUID.ToString() == toaCapCuu.ToaCapCuuGUID.ToString());
                        if (tcc != null)
                        {
                            tcc.MaToaCapCuu    = toaCapCuu.MaToaCapCuu;
                            tcc.NgayKeToa      = toaCapCuu.NgayKeToa;
                            tcc.BacSiKeToaGUID = toaCapCuu.BacSiKeToaGUID;
                            tcc.TenBenhNhan    = toaCapCuu.TenBenhNhan;
                            tcc.MaBenhNhan     = toaCapCuu.MaBenhNhan;
                            tcc.DiaChi         = toaCapCuu.DiaChi;
                            tcc.TenCongTy      = toaCapCuu.TenCongTy;
                            tcc.Note           = toaCapCuu.Note;
                            tcc.CreatedDate    = toaCapCuu.CreatedDate;
                            tcc.CreatedBy      = toaCapCuu.CreatedBy;
                            tcc.UpdatedDate    = toaCapCuu.UpdatedDate;
                            tcc.UpdatedBy      = toaCapCuu.UpdatedBy;
                            tcc.DeletedDate    = toaCapCuu.DeletedDate;
                            tcc.DeletedBy      = toaCapCuu.DeletedBy;
                            tcc.Status         = toaCapCuu.Status;
                            db.SubmitChanges();

                            string basSiKeToa = string.Empty;
                            if (tcc.DocStaff != null)
                            {
                                basSiKeToa = tcc.DocStaff.Contact.FullName;
                            }

                            desc += string.Format("-Toa cấp cứu GUID: '{0}', Mã toa cấp cứu: '{1}', Ngày kê toa: '{2}', Bác sĩ kê toa: '{3}', Bệnh nhân: '{4}', Ghi chú: '{5}'\n",
                                                  tcc.ToaCapCuuGUID.ToString(), tcc.MaToaCapCuu, tcc.NgayKeToa.ToString("dd/MM/yyyy HH:mm:ss"), basSiKeToa,
                                                  tcc.TenBenhNhan, tcc.Note);

                            //Delete chi tiet toa cấp cứu
                            if (deletedKeys != null && deletedKeys.Count > 0)
                            {
                                desc += "- Chi tiết toa cấp cứu được xóa:\n";
                                foreach (string key in deletedKeys)
                                {
                                    ChiTietToaCapCuu cttcc = db.ChiTietToaCapCuus.SingleOrDefault <ChiTietToaCapCuu>(c => c.ChiTietToaCapCuuGUID.ToString() == key);
                                    if (cttcc != null)
                                    {
                                        cttcc.DeletedDate = DateTime.Now;
                                        cttcc.DeletedBy   = Guid.Parse(Global.UserGUID);
                                        cttcc.Status      = (byte)Status.Deactived;

                                        desc += string.Format("  + GUID: '{0}', Tên cấp cứu: '{1}', Số lượng: '{2}'\n", cttcc.ChiTietToaCapCuuGUID.ToString(),
                                                              cttcc.KhoCapCuu.TenCapCuu, cttcc.SoLuong);
                                    }
                                }

                                db.SubmitChanges();
                            }


                            //Add chi tiet toa cấp cứu
                            if (addedList != null && addedList.Count > 0)
                            {
                                desc += "- Chi tiết toa cấp cứu được thêm:\n";
                                foreach (ChiTietToaCapCuu cttcc in addedList)
                                {
                                    cttcc.ToaCapCuuGUID = tcc.ToaCapCuuGUID;
                                    if (cttcc.ChiTietToaCapCuuGUID == Guid.Empty)
                                    {
                                        cttcc.ChiTietToaCapCuuGUID = Guid.NewGuid();
                                        db.ChiTietToaCapCuus.InsertOnSubmit(cttcc);
                                        db.SubmitChanges();

                                        desc += string.Format("  + GUID: '{0}', Tên cấp cứu: '{1}', Số lượng: '{2}'\n", cttcc.ChiTietToaCapCuuGUID.ToString(),
                                                              cttcc.KhoCapCuu.TenCapCuu, cttcc.SoLuong);
                                    }
                                    else
                                    {
                                        ChiTietToaCapCuu chiTietToaCapCuu = db.ChiTietToaCapCuus.SingleOrDefault <ChiTietToaCapCuu>(c => c.ChiTietToaCapCuuGUID == cttcc.ChiTietToaCapCuuGUID);
                                        if (chiTietToaCapCuu != null)
                                        {
                                            chiTietToaCapCuu.KhoCapCuuGUID = cttcc.KhoCapCuuGUID;
                                            chiTietToaCapCuu.SoLuong       = cttcc.SoLuong;
                                            chiTietToaCapCuu.Note          = cttcc.Note;
                                            chiTietToaCapCuu.Status        = (byte)Status.Actived;
                                            chiTietToaCapCuu.UpdatedDate   = cttcc.UpdatedDate;
                                            chiTietToaCapCuu.UpdatedBy     = cttcc.UpdatedBy;
                                            db.SubmitChanges();

                                            desc += string.Format("  + GUID: '{0}', Tên cấp cứu: '{1}', Số lượng: '{2}'\n",
                                                                  chiTietToaCapCuu.ChiTietToaCapCuuGUID.ToString(), chiTietToaCapCuu.KhoCapCuu.TenCapCuu, chiTietToaCapCuu.SoLuong);
                                        }
                                    }
                                }
                            }

                            //Tracking
                            desc = desc.Substring(0, desc.Length - 1);
                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin toa cấp cứu";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #15
0
        public static Result DeleteLoaiSieuAm(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        LoaiSieuAm l = db.LoaiSieuAms.SingleOrDefault <LoaiSieuAm>(ss => ss.LoaiSieuAmGUID.ToString() == key);
                        if (l != null)
                        {
                            l.DeletedDate = DateTime.Now;
                            l.DeletedBy   = Guid.Parse(Global.UserGUID);
                            l.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'\n",
                                                  l.LoaiSieuAmGUID.ToString(), l.TenSieuAm, l.ThuTu, l.InTrang2);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin loại siêu âm";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #16
0
        public static Result CapNhatTrangThaiPhieuThu(string phieuThuThuocGUID, bool daXuatHD, bool daThuTien, byte hinhThucThanhToan, string ghiChu)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();

                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    PhieuThuThuoc ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.PhieuThuThuocGUID.ToString() == phieuThuThuocGUID);
                    if (ptthuoc != null)
                    {
                        ptthuoc.UpdatedDate       = DateTime.Now;
                        ptthuoc.UpdatedBy         = Guid.Parse(Global.UserGUID);
                        ptthuoc.IsExported        = daXuatHD;
                        ptthuoc.ChuaThuTien       = !daThuTien;
                        ptthuoc.HinhThucThanhToan = hinhThucThanhToan;
                        ptthuoc.Notes             = ghiChu;

                        string maToaThuoc = string.Empty;
                        if (ptthuoc.ToaThuocGUID.Value != Guid.Empty)
                        {
                            maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc;
                        }

                        string desc = string.Format("Phiếu thu thuốc: GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Đã xuất HĐ: '{9}', Hình thức thanh toán: '{10}'",
                                                    ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                                    ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, ptthuoc.Notes, !ptthuoc.ChuaThuTien, ptthuoc.IsExported, ptthuoc.HinhThucThanhToan);

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Edit;
                        tk.Action       = "Sửa trạng thái phiếu thu thuốc";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #17
0
        public static Result InsertLoaiSieuAm(LoaiSieuAm loaiSieuAm, List <MauBaoCao> mauBaoCaoList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (loaiSieuAm.LoaiSieuAmGUID == null || loaiSieuAm.LoaiSieuAmGUID == Guid.Empty)
                    {
                        loaiSieuAm.LoaiSieuAmGUID = Guid.NewGuid();
                        db.LoaiSieuAms.InsertOnSubmit(loaiSieuAm);
                        db.SubmitChanges();

                        foreach (var mauBaoCao in mauBaoCaoList)
                        {
                            mauBaoCao.MauBaoCaoGUID  = Guid.NewGuid();
                            mauBaoCao.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID;
                            mauBaoCao.CreatedDate    = DateTime.Now;
                            mauBaoCao.CreatedBy      = Guid.Parse(Global.UserGUID);
                            db.MauBaoCaos.InsertOnSubmit(mauBaoCao);
                        }

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'",
                                              loaiSieuAm.LoaiSieuAmGUID.ToString(), loaiSieuAm.TenSieuAm, loaiSieuAm.ThuTu, loaiSieuAm.InTrang2);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin loại siêu âm";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        LoaiSieuAm lsa = db.LoaiSieuAms.SingleOrDefault <LoaiSieuAm>(s => s.LoaiSieuAmGUID.ToString() == loaiSieuAm.LoaiSieuAmGUID.ToString());
                        if (lsa != null)
                        {
                            lsa.TenSieuAm   = loaiSieuAm.TenSieuAm;
                            lsa.ThuTu       = loaiSieuAm.ThuTu;
                            lsa.InTrang2    = loaiSieuAm.InTrang2;
                            lsa.Path        = loaiSieuAm.Path;
                            lsa.UpdatedDate = loaiSieuAm.UpdatedDate;
                            lsa.UpdatedBy   = loaiSieuAm.UpdatedBy;
                            lsa.Status      = loaiSieuAm.Status;

                            //Delete mẫu báo cáo
                            var mbcs = lsa.MauBaoCaos;
                            foreach (var mbc in mbcs)
                            {
                                mbc.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                mbc.UpdatedDate = DateTime.Now;
                                mbc.Status      = (byte)Status.Deactived;
                            }

                            //Update mẫu báo cáo
                            foreach (var mbc in mauBaoCaoList)
                            {
                                MauBaoCao mauBaoCao = lsa.MauBaoCaos.Where(m => m.DoiTuong == mbc.DoiTuong).FirstOrDefault();
                                if (mauBaoCao == null)
                                {
                                    mbc.MauBaoCaoGUID  = Guid.NewGuid();
                                    mbc.LoaiSieuAmGUID = loaiSieuAm.LoaiSieuAmGUID;
                                    mbc.CreatedDate    = DateTime.Now;
                                    mbc.CreatedBy      = Guid.Parse(Global.UserGUID);
                                    db.MauBaoCaos.InsertOnSubmit(mbc);
                                }
                                else
                                {
                                    mauBaoCao.UpdatedBy   = Guid.Parse(Global.UserGUID);
                                    mauBaoCao.UpdatedDate = DateTime.Now;
                                    mauBaoCao.Template    = mbc.Template;
                                    mauBaoCao.Status      = (byte)Status.Actived;
                                }
                            }

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Tên siêu âm: '{1}', Thứ tự: '{2}', In trang 2: '{3}'",
                                                  lsa.LoaiSieuAmGUID.ToString(), lsa.TenSieuAm, lsa.ThuTu, lsa.InTrang2);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin loại siêu âm";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #18
0
        public static Result InsertLichKham(LichKham lichKham)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (lichKham.LichKhamGUID == null || lichKham.LichKhamGUID == Guid.Empty)
                    {
                        lichKham.LichKhamGUID = Guid.NewGuid();
                        db.LichKhams.InsertOnSubmit(lichKham);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Ngay: '{1}', Type: '{2}', Value: '{3}'",
                                              lichKham.LichKhamGUID.ToString(), lichKham.Ngay.ToString("dd/MM/yyyy"), lichKham.Type, lichKham.Value);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin lịch khám";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        LichKham lk = db.LichKhams.SingleOrDefault <LichKham>(l => l.LichKhamGUID == lichKham.LichKhamGUID);
                        if (lk != null)
                        {
                            lk.Value       = lichKham.Value;
                            lk.CreatedBy   = lichKham.CreatedBy;
                            lk.CreatedDate = lichKham.CreatedDate;
                            lk.DeletedBy   = lichKham.DeletedBy;
                            lk.DeletedDate = lichKham.DeletedDate;
                            lk.UpdatedBy   = lichKham.UpdatedBy;
                            lk.UpdatedDate = lichKham.UpdatedDate;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Ngay: '{1}', Type: '{2}', Value: '{3}'",
                                                  lk.LichKhamGUID.ToString(), lk.Ngay.ToString("dd/MM/yyyy"), lk.Type, lk.Value);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin lịch khám";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #19
0
        public static Result InsertKetQuaSieuAm(KetQuaSieuAm ketQuaSieuAm)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ketQuaSieuAm.KetQuaSieuAmGUID == null || ketQuaSieuAm.KetQuaSieuAmGUID == Guid.Empty)
                    {
                        ketQuaSieuAm.KetQuaSieuAmGUID = Guid.NewGuid();
                        db.KetQuaSieuAms.InsertOnSubmit(ketQuaSieuAm);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Ngày siêu âm: '{1}', Bệnh nhân: '{2}', Bác sĩ siêu âm: '{3}', Bác sĩ chỉ định: '{4}', Loại siêu âm: '{5}'",
                                              ketQuaSieuAm.KetQuaSieuAmGUID.ToString(), ketQuaSieuAm.NgaySieuAm.Value.ToString("dd/MM/yyyy HH:mm:ss"), ketQuaSieuAm.Patient.Contact.FullName,
                                              ketQuaSieuAm.BacSiSieuAmGUID.ToString(), ketQuaSieuAm.BacSiChiDinhGUID.ToString(), ketQuaSieuAm.LoaiSieuAm.TenSieuAm);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm kết quả siêu âm";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        KetQuaSieuAm kqsa = db.KetQuaSieuAms.SingleOrDefault <KetQuaSieuAm>(k => k.KetQuaSieuAmGUID == ketQuaSieuAm.KetQuaSieuAmGUID);
                        if (kqsa != null)
                        {
                            kqsa.NgaySieuAm       = ketQuaSieuAm.NgaySieuAm;
                            kqsa.PatientGUID      = ketQuaSieuAm.PatientGUID;
                            kqsa.BacSiSieuAmGUID  = ketQuaSieuAm.BacSiSieuAmGUID;
                            kqsa.BacSiChiDinhGUID = ketQuaSieuAm.BacSiChiDinhGUID;
                            kqsa.LoaiSieuAmGUID   = ketQuaSieuAm.LoaiSieuAmGUID;
                            kqsa.LamSang          = ketQuaSieuAm.LamSang;
                            kqsa.KetQuaSieuAm1    = ketQuaSieuAm.KetQuaSieuAm1;
                            kqsa.Hinh1            = ketQuaSieuAm.Hinh1;
                            kqsa.Hinh2            = ketQuaSieuAm.Hinh2;
                            kqsa.UpdatedBy        = ketQuaSieuAm.UpdatedBy;
                            kqsa.UpdatedDate      = ketQuaSieuAm.UpdatedDate;
                            kqsa.Status           = ketQuaSieuAm.Status;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Ngày siêu âm: '{1}', Bệnh nhân: '{2}', Bác sĩ siêu âm: '{3}', Bác sĩ chỉ định: '{4}', Loại siêu âm: '{5}'",
                                                  kqsa.KetQuaSieuAmGUID.ToString(), kqsa.NgaySieuAm.Value.ToString("dd/MM/yyyy HH:mm:ss"), kqsa.Patient.Contact.FullName,
                                                  kqsa.BacSiSieuAmGUID.ToString(), kqsa.BacSiChiDinhGUID.ToString(), kqsa.LoaiSieuAm.TenSieuAm);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa kết quả siêu âm";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
        public static Result DeleteBenhNhanNgoaiGoiKham(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        BenhNhanNgoaiGoiKham bnngk = db.BenhNhanNgoaiGoiKhams.SingleOrDefault <BenhNhanNgoaiGoiKham>(b => b.BenhNhanNgoaiGoiKhamGUID.ToString() == key);
                        if (bnngk != null)
                        {
                            bnngk.DeletedDate = DateTime.Now;
                            bnngk.DeletedBy   = Guid.Parse(Global.UserGUID);
                            bnngk.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Ngày khám: '{1}', Bệnh nhân: '{2}', Dịch vụ: '{3}', Lần đầu: '{4}'\n",
                                                  bnngk.BenhNhanNgoaiGoiKhamGUID.ToString(), bnngk.NgayKham.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  bnngk.Patient.Contact.FullName, bnngk.Service.Name, bnngk.LanDau == 0 ? "Lần đầu" : "Tái khám");
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa bệnh nhân ngoài gói khám";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #21
0
        public static Result InsertDichVuLamThem(DichVuLamThem dichVuLamThem)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();

                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    //Insert
                    if (dichVuLamThem.DichVuLamThemGUID == null || dichVuLamThem.DichVuLamThemGUID == Guid.Empty)
                    {
                        dichVuLamThem.DichVuLamThemGUID = Guid.NewGuid();
                        db.DichVuLamThems.InsertOnSubmit(dichVuLamThem);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Mã dịch vụ: '{1}', Tên dịch vụ: '{2}', Tên tiếng anh: '{3}', Giá: '{4}', Giảm: '{5}', Ngày sử dụng: '{6}', Đã thu tiền: '{7}'",
                                              dichVuLamThem.DichVuLamThemGUID.ToString(), dichVuLamThem.Service.Code, dichVuLamThem.Service.Name,
                                              dichVuLamThem.Service.EnglishName, dichVuLamThem.Price, dichVuLamThem.Discount,
                                              dichVuLamThem.ActiveDate.ToString("dd/MM/yyyy HH:mm:ss"), dichVuLamThem.DaThuTien);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm dịch vụ làm thêm";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        DichVuLamThem dvlt = db.DichVuLamThems.SingleOrDefault <DichVuLamThem>(s => s.DichVuLamThemGUID == dichVuLamThem.DichVuLamThemGUID);
                        if (dvlt != null)
                        {
                            dvlt.ServiceGUID = dichVuLamThem.ServiceGUID;
                            dvlt.ActiveDate  = dichVuLamThem.ActiveDate;
                            dvlt.Price       = dichVuLamThem.Price;
                            dvlt.Discount    = dichVuLamThem.Discount;
                            dvlt.DaThuTien   = dichVuLamThem.DaThuTien;
                            dvlt.Note        = dichVuLamThem.Note;
                            dvlt.CreatedDate = dichVuLamThem.CreatedDate;
                            dvlt.CreatedBy   = dichVuLamThem.CreatedBy;
                            dvlt.UpdatedDate = dichVuLamThem.UpdatedDate;
                            dvlt.UpdatedBy   = dichVuLamThem.UpdatedBy;
                            dvlt.DeletedDate = dichVuLamThem.DeletedDate;
                            dvlt.DeletedBy   = dichVuLamThem.DeletedBy;
                            dvlt.Status      = dichVuLamThem.Status;

                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Mã dịch vụ: '{1}', Tên dịch vụ: '{2}', Tên tiếng anh: '{3}', Giá: '{4}', Giảm: '{5}', Ngày sử dụng: '{6}', ContractMemberGUID: '{7}', Đã thu tiền: '{8}'",
                                                  dvlt.DichVuLamThemGUID.ToString(), dvlt.Service.Code, dvlt.Service.Name, dvlt.Service.EnglishName, dvlt.Price,
                                                  dvlt.Discount, dvlt.ActiveDate.ToString("dd/MM/yyyy HH:mm:ss"), dvlt.ContractMemberGUID.ToString(), dvlt.DaThuTien);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa dịch vụ làm thêm";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.Price;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #22
0
        public static Result InsertCongTacNgoaiGio(CongTacNgoaiGio ctng)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ctng.CongTacNgoaiGioGUID == null || ctng.CongTacNgoaiGioGUID == Guid.Empty)
                    {
                        ctng.CongTacNgoaiGioGUID = Guid.NewGuid();
                        db.CongTacNgoaiGios.InsertOnSubmit(ctng);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Ngày: '{1}', Họ tên: '{2}', Mục đích: '{3}', Giờ vào: '{4}', Giờ ra: '{5}', Kết quả đánh giá: '{6}', Người đề xuất: '{7}', Ghi chú: '{8}'",
                                              ctng.CongTacNgoaiGioGUID.ToString(), ctng.Ngay.ToString("dd/MM/yyyy"), ctng.DocStaff.Contact.FullName, ctng.MucDich, ctng.GioVao.Value.ToString("HH:mm"), ctng.GioRa.Value.ToString("HH:mm"),
                                              ctng.KetQuaDanhGia, ctng.DocStaff.Contact.FullName, ctng.GhiChu);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin công tác ngoài giờ";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        CongTacNgoaiGio congTacNgoaiGio = db.CongTacNgoaiGios.SingleOrDefault <CongTacNgoaiGio>(c => c.CongTacNgoaiGioGUID.ToString() == ctng.CongTacNgoaiGioGUID.ToString());
                        if (congTacNgoaiGio != null)
                        {
                            congTacNgoaiGio.Ngay            = ctng.Ngay;
                            congTacNgoaiGio.TenNguoiLam     = ctng.TenNguoiLam;
                            congTacNgoaiGio.MucDich         = ctng.MucDich;
                            congTacNgoaiGio.GioVao          = ctng.GioVao;
                            congTacNgoaiGio.GioRa           = ctng.GioRa;
                            congTacNgoaiGio.KetQuaDanhGia   = ctng.KetQuaDanhGia;
                            congTacNgoaiGio.NguoiDeXuatGUID = ctng.NguoiDeXuatGUID;
                            congTacNgoaiGio.GhiChu          = ctng.GhiChu;
                            congTacNgoaiGio.CreatedDate     = ctng.CreatedDate;
                            congTacNgoaiGio.CreatedBy       = ctng.CreatedBy;
                            congTacNgoaiGio.UpdatedDate     = ctng.UpdatedDate;
                            congTacNgoaiGio.UpdatedBy       = ctng.UpdatedBy;
                            congTacNgoaiGio.DeletedDate     = ctng.DeletedDate;
                            congTacNgoaiGio.DeletedBy       = ctng.DeletedBy;
                            congTacNgoaiGio.Status          = ctng.Status;

                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Ngày: '{1}', Họ tên: '{2}', Mục đích: '{3}', Giờ vào: '{4}', Giờ ra: '{5}', Kết quả đánh giá: '{6}', Người đề xuất: '{7}', Ghi chú: '{8}'",
                                                  congTacNgoaiGio.CongTacNgoaiGioGUID.ToString(), congTacNgoaiGio.Ngay.ToString("dd/MM/yyyy"), congTacNgoaiGio.DocStaff.Contact.FullName, congTacNgoaiGio.MucDich,
                                                  congTacNgoaiGio.GioVao.Value.ToString("HH:mm"), congTacNgoaiGio.GioRa.Value.ToString("HH:mm"), congTacNgoaiGio.KetQuaDanhGia, congTacNgoaiGio.DocStaff.Contact.FullName, congTacNgoaiGio.GhiChu);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin công tác ngoài giờ";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #23
0
        public static Result DeleteChiDinhs(List <string> chiDinhKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in chiDinhKeys)
                    {
                        ChiDinh chiDinh = db.ChiDinhs.SingleOrDefault <ChiDinh>(c => c.ChiDinhGUID.ToString() == key);
                        if (chiDinh != null)
                        {
                            chiDinh.DeletedDate = DateTime.Now;
                            chiDinh.DeletedBy   = Guid.Parse(Global.UserGUID);
                            chiDinh.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Mã chỉ định: '{1}', Ngày chỉ định: '{2}', Bác sĩ chỉ định: '{3}', Bệnh nhân: '{4}'\n",
                                                  chiDinh.ChiDinhGUID.ToString(), chiDinh.MaChiDinh, chiDinh.NgayChiDinh.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  chiDinh.DocStaff.Contact.FullName, chiDinh.Patient.Contact.FullName);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin chỉ định";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #24
0
        public static Result DeleteCongTacNgoaiGio(List <string> congtacNgoaiKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in congtacNgoaiKeys)
                    {
                        CongTacNgoaiGio ctng = db.CongTacNgoaiGios.SingleOrDefault <CongTacNgoaiGio>(c => c.CongTacNgoaiGioGUID.ToString() == key);
                        if (ctng != null)
                        {
                            ctng.DeletedDate = DateTime.Now;
                            ctng.DeletedBy   = Guid.Parse(Global.UserGUID);
                            ctng.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Ngày: '{1}', Họ tên: '{2}', Mục đích: '{3}', Giờ vào: '{4}', Giờ ra: '{5}', Kết quả đánh giá: '{6}', Người đề xuất: '{7}', Ghi chú: '{8}'\n",
                                                  ctng.CongTacNgoaiGioGUID.ToString(), ctng.Ngay.ToString("dd/MM/yyyy"), ctng.DocStaff.Contact.FullName, ctng.MucDich, ctng.GioVao.Value.ToString("HH:mm"), ctng.GioRa.Value.ToString("HH:mm"),
                                                  ctng.KetQuaDanhGia, ctng.DocStaff.Contact.FullName, ctng.GhiChu);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin công tác ngoài giờ";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #25
0
        public static Result UpdateChiDinh(ChiDinh chiDinh, string serverGUID)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string  desc = string.Empty;
                ChiDinh cd   = db.ChiDinhs.SingleOrDefault <ChiDinh>(c => c.ChiDinhGUID.ToString() == chiDinh.ChiDinhGUID.ToString());
                if (cd != null)
                {
                    cd.MaChiDinh        = chiDinh.MaChiDinh;
                    cd.NgayChiDinh      = chiDinh.NgayChiDinh;
                    cd.BacSiChiDinhGUID = chiDinh.BacSiChiDinhGUID;
                    cd.BenhNhanGUID     = chiDinh.BenhNhanGUID;
                    cd.CreatedDate      = chiDinh.CreatedDate;
                    cd.CreatedBy        = chiDinh.CreatedBy;
                    cd.UpdatedDate      = chiDinh.UpdatedDate;
                    cd.UpdatedBy        = chiDinh.UpdatedBy;
                    cd.DeletedDate      = chiDinh.DeletedDate;
                    cd.DeletedBy        = chiDinh.DeletedBy;
                    cd.Status           = chiDinh.Status;

                    ChiTietChiDinh ctcd = db.ChiTietChiDinhs.SingleOrDefault(c => c.ChiDinhGUID == cd.ChiDinhGUID &&
                                                                             c.Status == (byte)Status.Actived);

                    if (ctcd != null)
                    {
                        ctcd.ServiceGUID = Guid.Parse(serverGUID);
                    }

                    db.SubmitChanges();

                    desc += string.Format("- Chỉ định: GUID: '{0}', Mã chỉ định: '{1}', Ngày chỉ định: '{2}', Bác sĩ chỉ định: '{3}', Bệnh nhân: '{4}'\n",
                                          cd.ChiDinhGUID.ToString(), cd.MaChiDinh, cd.NgayChiDinh.ToString("dd/MM/yyyy HH:mm:ss"),
                                          cd.DocStaff.Contact.FullName, cd.Patient.Contact.FullName);

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Edit;
                    tk.Action       = "Sửa thông tin chỉ định";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);
                    db.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #26
0
        public static Result InsertThongTinCapCuu(KhoCapCuu khoCapCuu)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (khoCapCuu.KhoCapCuuGUID == null || khoCapCuu.KhoCapCuuGUID == Guid.Empty)
                    {
                        khoCapCuu.KhoCapCuuGUID = Guid.NewGuid();
                        db.KhoCapCuus.InsertOnSubmit(khoCapCuu);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Tên cấp cứu: '{1}', ĐVT: '{2}'",
                                              khoCapCuu.KhoCapCuuGUID.ToString(), khoCapCuu.TenCapCuu, khoCapCuu.DonViTinh);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin cấp cứu";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        KhoCapCuu kcc = db.KhoCapCuus.SingleOrDefault <KhoCapCuu>(k => k.KhoCapCuuGUID == khoCapCuu.KhoCapCuuGUID);
                        if (kcc != null)
                        {
                            kcc.TenCapCuu   = khoCapCuu.TenCapCuu;
                            kcc.DonViTinh   = khoCapCuu.DonViTinh;
                            kcc.Note        = khoCapCuu.Note;
                            kcc.CreatedDate = khoCapCuu.CreatedDate;
                            kcc.CreatedBy   = khoCapCuu.CreatedBy;
                            kcc.UpdatedDate = khoCapCuu.UpdatedDate;
                            kcc.UpdatedBy   = khoCapCuu.UpdatedBy;
                            kcc.DeletedDate = khoCapCuu.DeletedDate;
                            kcc.DeletedBy   = khoCapCuu.DeletedBy;
                            kcc.Status      = khoCapCuu.Status;

                            //Update DVT to NhapKhoCapCuu
                            var nhapKhoCapCuus = kcc.NhapKhoCapCuus;
                            foreach (var nk in nhapKhoCapCuus)
                            {
                                if (kcc.DonViTinh == nk.DonViTinhQuiDoi)
                                {
                                    continue;
                                }
                                nk.DonViTinhQuiDoi = kcc.DonViTinh;
                                if (nk.DonViTinhNhap != "Hộp" && nk.DonViTinhNhap != "Vỉ")
                                {
                                    nk.DonViTinhNhap = kcc.DonViTinh;
                                }
                                else if (nk.DonViTinhNhap == "Vỉ" && kcc.DonViTinh != "Viên")
                                {
                                    nk.DonViTinhNhap = "Hộp";
                                }
                            }

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Tên cấp cứu: '{1}', ĐVT: '{2}'",
                                                  kcc.KhoCapCuuGUID.ToString(), kcc.TenCapCuu, kcc.DonViTinh);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin cấp cứu";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #27
0
        public static Result DeleteCompany(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        Company c = db.Companies.SingleOrDefault <Company>(cc => cc.CompanyGUID.ToString() == key);
                        if (c != null)
                        {
                            c.DeletedDate = DateTime.Now;
                            c.DeletedBy   = Guid.Parse(Global.UserGUID);
                            c.Status      = (byte)Status.Deactived;

                            foreach (var cm in c.CompanyMembers)
                            {
                                cm.Status = (byte)Status.Deactived;
                            }

                            desc += string.Format("- GUID: '{0}', Mã cty: '{1}', Tên cty: '{2}', Địa chỉ: '{3}', Điện thoại: '{4}', Fax: '{5}', Website: '{6}', Mã số thuế: '{7}'\n",
                                                  c.CompanyGUID.ToString(), c.MaCty, c.TenCty, c.DiaChi, c.Dienthoai, c.Fax, c.Website, c.MaSoThue);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin công ty";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #28
0
        public static Result DeleteThongTinCapCuu(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in keys)
                    {
                        KhoCapCuu kcc = db.KhoCapCuus.SingleOrDefault <KhoCapCuu>(k => k.KhoCapCuuGUID.ToString() == key);
                        if (kcc != null)
                        {
                            kcc.DeletedDate = DateTime.Now;
                            kcc.DeletedBy   = Guid.Parse(Global.UserGUID);
                            kcc.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Tên cấp cứu: '{1}', ĐVT: '{2}'\n", kcc.KhoCapCuuGUID.ToString(), kcc.TenCapCuu, kcc.DonViTinh);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin cấp cứu";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #29
0
        public static Result DeleteServiceGroup(List <string> serviceGroupKeys)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc = string.Empty;
                    foreach (string key in serviceGroupKeys)
                    {
                        ServiceGroup g = db.ServiceGroups.SingleOrDefault <ServiceGroup>(gg => gg.ServiceGroupGUID.ToString() == key);
                        if (g != null)
                        {
                            g.DeletedDate = DateTime.Now;
                            g.DeletedBy   = Guid.Parse(Global.UserGUID);
                            g.Status      = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Mã nhóm: '{1}', Tên nhóm: '{2}'\n", g.ServiceGroupGUID.ToString(), g.Code, g.Name);
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin nhóm dịch vụ";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Example #30
0
        public static Result InsertKetQuaSoiCTC(KetQuaSoiCTC ketQuaSoiCTC)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ketQuaSoiCTC.KetQuaSoiCTCGUID == null || ketQuaSoiCTC.KetQuaSoiCTCGUID == Guid.Empty)
                    {
                        ketQuaSoiCTC.KetQuaSoiCTCGUID = Guid.NewGuid();
                        db.KetQuaSoiCTCs.InsertOnSubmit(ketQuaSoiCTC);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Ngày khám: '{1}', Bệnh nhân: '{2}', Bác sĩ soi: '{3}', Kết luận: '{4}', Đề nghị: '{5}', Âm hộ: '{6}', Âm đạo: '{7}', CTC: '{8}', Biểu mô lát: '{9}', Mô đệm: '{10}', Ranh giới lát trụ: '{11}', Sau Acid Acetic: '{12}', Sau Lugol: '{13}'\n",
                                              ketQuaSoiCTC.KetQuaSoiCTCGUID.ToString(), ketQuaSoiCTC.NgayKham.ToString("dd/MM/yyyy HH:mm:ss"),
                                              ketQuaSoiCTC.Patient.Contact.FullName, ketQuaSoiCTC.DocStaff.Contact.FullName,
                                              ketQuaSoiCTC.KetLuan, ketQuaSoiCTC.DeNghi, ketQuaSoiCTC.AmHo, ketQuaSoiCTC.AmDao, ketQuaSoiCTC.CTC, ketQuaSoiCTC.BieuMoLat,
                                              ketQuaSoiCTC.MoDem, ketQuaSoiCTC.RanhGioiLatTru, ketQuaSoiCTC.SauAcidAcetic, ketQuaSoiCTC.SauLugol);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin khám CTC";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        KetQuaSoiCTC kqsctc = db.KetQuaSoiCTCs.SingleOrDefault <KetQuaSoiCTC>(k => k.KetQuaSoiCTCGUID == ketQuaSoiCTC.KetQuaSoiCTCGUID);
                        if (kqsctc != null)
                        {
                            kqsctc.NgayKham       = ketQuaSoiCTC.NgayKham;
                            kqsctc.PatientGUID    = ketQuaSoiCTC.PatientGUID;
                            kqsctc.BacSiSoi       = ketQuaSoiCTC.BacSiSoi;
                            kqsctc.KetLuan        = ketQuaSoiCTC.KetLuan;
                            kqsctc.DeNghi         = ketQuaSoiCTC.DeNghi;
                            kqsctc.Hinh1          = ketQuaSoiCTC.Hinh1;
                            kqsctc.Hinh2          = ketQuaSoiCTC.Hinh2;
                            kqsctc.AmHo           = ketQuaSoiCTC.AmHo;
                            kqsctc.AmDao          = ketQuaSoiCTC.AmDao;
                            kqsctc.CTC            = ketQuaSoiCTC.CTC;
                            kqsctc.BieuMoLat      = ketQuaSoiCTC.BieuMoLat;
                            kqsctc.MoDem          = ketQuaSoiCTC.MoDem;
                            kqsctc.RanhGioiLatTru = ketQuaSoiCTC.RanhGioiLatTru;
                            kqsctc.SauAcidAcetic  = ketQuaSoiCTC.SauAcidAcetic;
                            kqsctc.SauLugol       = ketQuaSoiCTC.SauLugol;
                            kqsctc.CreatedBy      = ketQuaSoiCTC.CreatedBy;
                            kqsctc.CreatedDate    = ketQuaSoiCTC.CreatedDate;
                            kqsctc.DeletedBy      = ketQuaSoiCTC.DeletedBy;
                            kqsctc.DeletedDate    = ketQuaSoiCTC.DeletedDate;
                            kqsctc.UpdatedBy      = ketQuaSoiCTC.UpdatedBy;
                            kqsctc.UpdatedDate    = ketQuaSoiCTC.UpdatedDate;
                            kqsctc.Status         = ketQuaSoiCTC.Status;
                            db.SubmitChanges();

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Ngày khám: '{1}', Bệnh nhân: '{2}', Bác sĩ soi: '{3}', Kết luận: '{4}', Đề nghị: '{5}', Âm hộ: '{6}', Âm đạo: '{7}', CTC: '{8}', Biểu mô lát: '{9}', Mô đệm: '{10}', Ranh giới lát trụ: '{11}', Sau Acid Acetic: '{12}', Sau Lugol: '{13}'\n",
                                                  kqsctc.KetQuaSoiCTCGUID.ToString(), kqsctc.NgayKham.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  kqsctc.Patient.Contact.FullName, kqsctc.DocStaff.Contact.FullName,
                                                  kqsctc.KetLuan, kqsctc.DeNghi, kqsctc.AmHo, kqsctc.AmDao, kqsctc.CTC, kqsctc.BieuMoLat,
                                                  kqsctc.MoDem, kqsctc.RanhGioiLatTru, kqsctc.SauAcidAcetic, kqsctc.SauLugol);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin khám CTC";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }