private void OnCapNhatBenhNhan()
        {
            if (dgXetNghiem.SelectedRows == null || dgXetNghiem.SelectedRows.Count <= 0)
            {
                MsgBox.Show(Application.ProductName, "Vui lòng chọn 1 xét nghiệm để cập nhật bệnh nhân.", IconType.Information);
                return;
            }

            DataRow row = (dgXetNghiem.SelectedRows[0].DataBoundItem as DataRowView).Row;

            if (row == null)
            {
                return;
            }

            dlgSelectPatient dlg = new dlgSelectPatient(PatientSearchType.BenhNhan);

            if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                DataRow patientRow = dlg.PatientRow;
                if (patientRow != null)
                {
                    KetQuaXetNghiem_CellDyn3200 kqxn = new KetQuaXetNghiem_CellDyn3200();
                    kqxn.KQXN_CellDyn3200GUID = Guid.Parse(row["KQXN_CellDyn3200GUID"].ToString());
                    kqxn.PatientGUID          = Guid.Parse(patientRow["PatientGUID"].ToString());
                    Result result = XetNghiem_CellDyn3200Bus.UpdatePatient(kqxn);
                    if (result.IsOK)
                    {
                        row["PatientGUID"] = patientRow["PatientGUID"];
                        row["FileNum"]     = patientRow["FileNum"];
                        row["FullName"]    = patientRow["FullName"];
                        row["DobStr"]      = patientRow["DobStr"];
                        row["GenderAsStr"] = patientRow["GenderAsStr"];

                        OnDisplayChiTietKetQuaXetNghiem(row["KQXN_CellDyn3200GUID"].ToString());
                    }
                    else
                    {
                        MsgBox.Show(Application.ProductName, result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdatePatient"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdatePatient"));
                    }
                }
            }
        }
예제 #2
0
        public static Result UpdateChiSoKetQuaXetNghiem(ChiTietKetQuaXetNghiem_CellDyn3200 chiTietKQXN, ref string binhThuong)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    ChiTietKetQuaXetNghiem_CellDyn3200 ctkqxn = db.ChiTietKetQuaXetNghiem_CellDyn3200s.SingleOrDefault <ChiTietKetQuaXetNghiem_CellDyn3200>(c => c.ChiTietKQXN_CellDyn3200GUID == chiTietKQXN.ChiTietKQXN_CellDyn3200GUID);
                    if (ctkqxn != null)
                    {
                        ctkqxn.UpdatedDate = DateTime.Now;
                        ctkqxn.UpdatedBy   = Guid.Parse(Global.UserGUID);
                        ctkqxn.Status      = (byte)Status.Actived;
                        ctkqxn.TestResult  = chiTietKQXN.TestResult;
                        ctkqxn.TestPercent = chiTietKQXN.TestPercent;
                        ctkqxn.FromValue   = chiTietKQXN.FromValue;
                        ctkqxn.ToValue     = chiTietKQXN.ToValue;
                        ctkqxn.FromPercent = chiTietKQXN.FromPercent;
                        ctkqxn.ToPercent   = chiTietKQXN.ToPercent;
                        ctkqxn.DonVi       = chiTietKQXN.DonVi;
                        ctkqxn.LamThem     = chiTietKQXN.LamThem;

                        KetQuaXetNghiem_CellDyn3200 kqxn = ctkqxn.KetQuaXetNghiem_CellDyn3200;
                        string tenBenhNhan = string.Empty;
                        string fileNum     = string.Empty;
                        if (kqxn.PatientGUID != null)
                        {
                            PatientView patient = db.PatientViews.SingleOrDefault <PatientView>(p => p.PatientGUID == kqxn.PatientGUID);
                            if (patient != null)
                            {
                                fileNum     = patient.FileNum;
                                tenBenhNhan = patient.FullName;
                            }
                        }

                        //
                        double?fromValue = null;
                        double?toValue   = null;
                        //double? fromPercent = null;
                        //double? toPercent = null;
                        string donVi = string.Empty;

                        if (ctkqxn.FromValue.HasValue)
                        {
                            fromValue = ctkqxn.FromValue.Value;
                        }

                        if (ctkqxn.ToValue.HasValue)
                        {
                            toValue = ctkqxn.ToValue.Value;
                        }

                        //if (ctkqxn.FromPercent.HasValue)
                        //    fromPercent = ctkqxn.FromPercent.Value;

                        //if (ctkqxn.ToPercent.HasValue)
                        //    toPercent = ctkqxn.ToPercent.Value;

                        if (ctkqxn.DonVi != null && ctkqxn.DonVi != string.Empty)
                        {
                            donVi = ctkqxn.DonVi;
                        }

                        double    testResult = ctkqxn.TestResult.Value;
                        TinhTrang tinhTrang  = TinhTrang.BinhThuong;

                        if (fromValue != null && toValue != null)
                        {
                            //if (fromPercent != null || toPercent != null)
                            //    binhThuong = string.Format("({0:F2} - {1:F2})", fromValue.Value, toValue.Value);
                            //else
                            if (donVi != string.Empty)
                            {
                                binhThuong = string.Format("({0:F2}-{1:F2} {2})", fromValue.Value, toValue.Value, donVi);
                            }
                            else
                            {
                                binhThuong = string.Format("({0:F2}-{1:F2})", fromValue.Value, toValue.Value);
                            }

                            if (testResult < fromValue.Value || testResult > toValue.Value)
                            {
                                tinhTrang = TinhTrang.BatThuong;
                            }
                        }
                        else if (fromValue != null)
                        {
                            //if (fromPercent != null || toPercent != null)
                            //    binhThuong = string.Format("(> {0:F2})", fromValue.Value);
                            //else
                            if (donVi != string.Empty)
                            {
                                binhThuong = string.Format("(>{0:F2} {1})", fromValue.Value, donVi);
                            }
                            else
                            {
                                binhThuong = string.Format("(>{0:F2})", fromValue.Value);
                            }

                            if (testResult <= fromValue.Value)
                            {
                                tinhTrang = TinhTrang.BatThuong;
                            }
                        }
                        else
                        {
                            //if (fromPercent != null || toPercent != null)
                            //    binhThuong = string.Format("(< {0:F2})", toValue.Value);
                            //else
                            if (donVi != string.Empty)
                            {
                                binhThuong = string.Format("(<{0:F2} {1})", toValue.Value, donVi);
                            }
                            else
                            {
                                binhThuong = string.Format("(<{0:F2})", toValue.Value);
                            }

                            if (testResult >= toValue.Value)
                            {
                                tinhTrang = TinhTrang.BatThuong;
                            }
                        }

                        //if (fromPercent != null && toPercent != null)
                        //{
                        //    double testPercent = ctkqxn.TestPercent.Value;
                        //    percent = string.Format("{0:F2}% ({1:F2} - {2:F2} {3})", testPercent, fromPercent.Value, toPercent.Value, donVi);

                        //    if (tinhTrang == TinhTrang.BinhThuong)
                        //    {
                        //        if (testPercent < fromPercent.Value || testPercent > toPercent.Value)
                        //            tinhTrang = TinhTrang.BatThuong;
                        //    }
                        //}
                        //else if (fromPercent != null)
                        //{
                        //    double testPercent = ctkqxn.TestPercent.Value;
                        //    percent = string.Format("{0:F2}% (> {1:F2} {2})", testPercent, fromPercent.Value, donVi);

                        //    if (tinhTrang == TinhTrang.BinhThuong)
                        //    {
                        //        if (testPercent <= fromPercent.Value)
                        //            tinhTrang = TinhTrang.BatThuong;
                        //    }
                        //}
                        //else if (toPercent != null)
                        //{
                        //    double testPercent = ctkqxn.TestPercent.Value;
                        //    percent = string.Format("{0:F2}% (< {1:F2} {2})", testPercent, toPercent.Value, donVi);

                        //    if (tinhTrang == TinhTrang.BinhThuong)
                        //    {
                        //        if (testPercent >= toPercent.Value)
                        //            tinhTrang = TinhTrang.BatThuong;
                        //    }
                        //}

                        chiTietKQXN.TinhTrang = (byte)tinhTrang;

                        //

                        desc += string.Format("- GUID: '{0}', Mã bệnh nhân: '{1}', Tên bệnh nhân: '{2}', Ngày xét nghiệm: '{3}', Tên xét nghiệm: '{4}', Kết quả: '{5}', % kết quả: '{6}'",
                                              kqxn.KQXN_CellDyn3200GUID.ToString(), fileNum, tenBenhNhan, kqxn.NgayXN.Value.ToString("dd/MM/yyyy HH:mm:ss"), ctkqxn.TenXetNghiem, ctkqxn.TestResult, ctkqxn.TestPercent);

                        //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       = "Cập nhật chỉ số kết quả xét nghiệm celldyn 3200";
                        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);
        }
예제 #3
0
        public static Result UpdatePatient(KetQuaXetNghiem_CellDyn3200 ketQuaXetNghiem)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    KetQuaXetNghiem_CellDyn3200 kqxn = db.KetQuaXetNghiem_CellDyn3200s.SingleOrDefault <KetQuaXetNghiem_CellDyn3200>(k => k.KQXN_CellDyn3200GUID == ketQuaXetNghiem.KQXN_CellDyn3200GUID &&
                                                                                                                                     k.Status == (byte)Status.Actived);

                    if (kqxn != null)
                    {
                        kqxn.UpdatedDate = DateTime.Now;
                        kqxn.UpdatedBy   = Guid.Parse(Global.UserGUID);
                        kqxn.PatientGUID = ketQuaXetNghiem.PatientGUID;

                        string tenBenhNhan = string.Empty;
                        string fileNum     = string.Empty;
                        if (ketQuaXetNghiem.PatientGUID != null)
                        {
                            PatientView patient = db.PatientViews.SingleOrDefault <PatientView>(p => p.PatientGUID == ketQuaXetNghiem.PatientGUID);
                            if (patient != null)
                            {
                                fileNum     = patient.FileNum;
                                tenBenhNhan = patient.FullName;
                            }
                        }

                        desc += string.Format("GUID: '{0}', Mã bệnh nhân: '{1}', Tên bệnh nhân: '{2}', Ngày xét nghiệm: '{3}'",
                                              kqxn.KQXN_CellDyn3200GUID.ToString(), fileNum, tenBenhNhan, kqxn.NgayXN.Value.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.Edit;
                        tk.Action       = "Cập nhật bệnh nhân xét nghiệm celldyn 3200";
                        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);
        }
예제 #4
0
        public static Result DeleteChiTietKetQuaXetNghiem(List <string> keys)
        {
            Result     result = new Result();
            MMOverride db     = null;

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

                            KetQuaXetNghiem_CellDyn3200 kqxn = ctkqxn.KetQuaXetNghiem_CellDyn3200;
                            string tenBenhNhan = string.Empty;
                            string fileNum     = string.Empty;
                            if (kqxn.PatientGUID != null)
                            {
                                PatientView patient = db.PatientViews.SingleOrDefault <PatientView>(p => p.PatientGUID == kqxn.PatientGUID);
                                if (patient != null)
                                {
                                    fileNum     = patient.FileNum;
                                    tenBenhNhan = patient.FullName;
                                }
                            }

                            desc += string.Format("- GUID: '{0}', Mã bệnh nhân: '{1}', Tên bệnh nhân: '{2}', Ngày xét nghiệm: '{3}', Tên xét nghiệm: '{4}', Kết quả: '{5}', % kết quả: '{6}'\n",
                                                  kqxn.KQXN_CellDyn3200GUID.ToString(), fileNum, tenBenhNhan, kqxn.NgayXN.Value.ToString("dd/MM/yyyy HH:mm:ss"), ctkqxn.TenXetNghiem, ctkqxn.TestResult, ctkqxn.TestPercent);
                        }
                    }

                    //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 chi tiết kết quả xét nghiệm celldyn 3200";
                    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);
        }
예제 #5
0
        public static Result InsertKQXN(List <TestResult_CellDyn3200> testResults)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    foreach (TestResult_CellDyn3200 testResult in testResults)
                    {
                        PatientView patient = db.PatientViews.SingleOrDefault <PatientView>(p => p.FileNum.ToLower().Trim() == testResult.KetQuaXetNghiem.SpecimenID.Trim().ToLower());

                        KetQuaXetNghiem_CellDyn3200 kqxn = db.KetQuaXetNghiem_CellDyn3200s.SingleOrDefault <KetQuaXetNghiem_CellDyn3200>(k => k.SpecimenID.Trim().ToLower() == testResult.KetQuaXetNghiem.SpecimenID.Trim().ToLower() &&
                                                                                                                                         k.OperatorID.Trim().ToLower() == testResult.KetQuaXetNghiem.OperatorID.Trim().ToLower() && k.NgayXN == testResult.KetQuaXetNghiem.NgayXN);

                        string ketQuaXetNghiemGUID = string.Empty;
                        if (kqxn == null) //Add New
                        {
                            testResult.KetQuaXetNghiem.KQXN_CellDyn3200GUID = Guid.NewGuid();
                            testResult.KetQuaXetNghiem.CreatedDate          = DateTime.Now;
                            if (Global.UserGUID != string.Empty)
                            {
                                testResult.KetQuaXetNghiem.CreatedBy = Guid.Parse(Global.UserGUID);
                            }
                            if (patient != null)
                            {
                                testResult.KetQuaXetNghiem.PatientGUID = patient.PatientGUID;
                            }
                            db.KetQuaXetNghiem_CellDyn3200s.InsertOnSubmit(testResult.KetQuaXetNghiem);
                            db.SubmitChanges();

                            ketQuaXetNghiemGUID = testResult.KetQuaXetNghiem.KQXN_CellDyn3200GUID.ToString();
                        }
                        else //Update
                        {
                            kqxn.UpdatedDate = DateTime.Now;
                            if (Global.UserGUID != string.Empty)
                            {
                                kqxn.UpdatedBy = Guid.Parse(Global.UserGUID);
                            }
                            if (patient != null)
                            {
                                kqxn.PatientGUID = patient.PatientGUID;
                            }
                            kqxn.Status         = (byte)Status.Actived;
                            kqxn.MessageType    = testResult.KetQuaXetNghiem.MessageType;
                            kqxn.InstrumentType = testResult.KetQuaXetNghiem.InstrumentType;
                            kqxn.SerialNum      = testResult.KetQuaXetNghiem.SerialNum;
                            kqxn.SequenceNum    = testResult.KetQuaXetNghiem.SequenceNum;
                            kqxn.SpareField     = testResult.KetQuaXetNghiem.SpareField;
                            kqxn.SpecimenType   = testResult.KetQuaXetNghiem.SpecimenType;
                            kqxn.SpecimenID     = testResult.KetQuaXetNghiem.SpecimenID;
                            kqxn.SpecimenName   = testResult.KetQuaXetNghiem.SpecimenName;
                            kqxn.PatientID      = testResult.KetQuaXetNghiem.PatientID;
                            kqxn.SpecimenSex    = testResult.KetQuaXetNghiem.SpecimenSex;
                            kqxn.SpecimenDOB    = testResult.KetQuaXetNghiem.SpecimenDOB;
                            kqxn.DrName         = testResult.KetQuaXetNghiem.DrName;
                            kqxn.OperatorID     = testResult.KetQuaXetNghiem.OperatorID;
                            kqxn.NgayXN         = testResult.KetQuaXetNghiem.NgayXN;
                            kqxn.CollectionDate = testResult.KetQuaXetNghiem.CollectionDate;
                            kqxn.CollectionTime = testResult.KetQuaXetNghiem.CollectionTime;
                            kqxn.Comment        = testResult.KetQuaXetNghiem.Comment;
                            db.SubmitChanges();
                            ketQuaXetNghiemGUID = kqxn.KQXN_CellDyn3200GUID.ToString();
                        }

                        foreach (ChiTietKetQuaXetNghiem_CellDyn3200 r in testResult.ChiTietKetQuaXetNghiem)
                        {
                            ChiTietKetQuaXetNghiem_CellDyn3200 ctkqxn = db.ChiTietKetQuaXetNghiem_CellDyn3200s.SingleOrDefault <ChiTietKetQuaXetNghiem_CellDyn3200>(c => c.KQXN_CellDyn3200GUID.ToString() == ketQuaXetNghiemGUID &&
                                                                                                                                                                    c.TenXetNghiem.Trim().ToLower() == r.TenXetNghiem.Trim().ToLower());

                            if (ctkqxn == null) //Add New
                            {
                                r.ChiTietKQXN_CellDyn3200GUID = Guid.NewGuid();
                                r.KQXN_CellDyn3200GUID        = Guid.Parse(ketQuaXetNghiemGUID);
                                r.CreatedDate = DateTime.Now;
                                if (Global.UserGUID != string.Empty)
                                {
                                    r.CreatedBy = Guid.Parse(Global.UserGUID);
                                }
                                db.ChiTietKetQuaXetNghiem_CellDyn3200s.InsertOnSubmit(r);
                            }
                            else //Update
                            {
                                ctkqxn.UpdatedDate = DateTime.Now;
                                if (Global.UserGUID != string.Empty)
                                {
                                    ctkqxn.UpdatedBy = Guid.Parse(Global.UserGUID);
                                }

                                ctkqxn.TenXetNghiem = r.TenXetNghiem;
                                ctkqxn.TestResult   = r.TestResult;
                                ctkqxn.TestPercent  = r.TestPercent;
                                ctkqxn.TinhTrang    = (byte)TinhTrang.BinhThuong;
                                ctkqxn.Status       = (byte)Status.Actived;
                            }
                        }
                    }

                    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);
        }