예제 #1
0
        public static decimal[] CalculateTestPrice(SampleTest sampleTest, SmartCollection<ClientPricing> discounts, Priority priority, SmartCollection<PricingRule> matrixItems, int analytes, decimal basePrice)
        {
            decimal[] pricingArray = new decimal[2];

            // PricingArray[0] = Total Price
            // PricingArray[1] = RUSH Only additional charge for invoicing only not used in calculations

            decimal price = 0; // Calculated set and returned
            decimal testPrice = 0;
            decimal priorityPriceAdjustment = 0;
            decimal matrixPrice = 0;
            decimal discount = 0;

            if (sampleTest.DiscountAllowedYN) {
                if (matrixItems.Count > 0) {
                    matrixPrice = testPrice * matrixItems.Sum(x => x.PriceAdjustment);
                    if (matrixPrice <= 0) matrixPrice = 0;
                }
            }

            if (discounts.Count > 0) {
                discount = (matrixPrice + testPrice) * (decimal)discounts.Sum(x => x.Discount);
                if (!sampleTest.DiscountAllowedYN) discount = 0;
                //if (discount <= 0) discount = 0;
            }
            priorityPriceAdjustment = testPrice * priority.PriceAdjustment;

            //if (priority.DiscountAllowedYN) {
                //Might need to create line item detail here for invoicing.
                //if (discounts.Count > 0) {
                    //priorityPriceAdjustment = priorityPriceAdjustment - (priorityPriceAdjustment * (decimal)discounts.Sum(x => x.Discount));
                    //if (priorityPriceAdjustment <= 0) priorityPriceAdjustment = 0;
                //}
            //}

            if (priority.PriorityName.ToUpper().Contains("RUSH"))
                pricingArray[1] = priorityPriceAdjustment;

            price = (testPrice + matrixPrice + priorityPriceAdjustment) - discount;

            if (price <= 0) price = 0;

            pricingArray[0] = Math.Round(price, 2);

            return pricingArray;
        }
예제 #2
0
        private SmartCollection<SampleTest> GetWorkLoad(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, CatalogItem filterItem, SmartCollection<Analyte> filterAnalytes, DateTime beginStartDate, DateTime beginEndDate, Identification identification)
        {
            try
            {
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();
                string sqlOrderBy = string.Empty;
                string sqlTest = string.Empty;
                string sqlAnalyst = string.Empty;
                string sqlDepartment = string.Empty;
                string sqlBeginDate = string.Empty;
                string sqlAnalytes = string.Empty;

                if (filterItem.TestId > 0)
                {
                    sqlTest = "AND sampleTest.testId = @TestId ";
                }
                else
                {
                    sqlTest = "AND sampleTest.testId >= @TestId ";
                }
                if (filterItem.AnalystId > 0)
                {
                    sqlAnalyst = "AND sampleTest.analystid = @AnalystId ";
                }
                else
                {
                    sqlAnalyst = "AND sampleTest.analystid >= @AnalystId ";
                }
                if (filterItem.DepartmentId > 0)
                {
                    sqlDepartment = "AND sampleTest.departmentid = @DepartmentId ";
                }
                else
                {
                    sqlDepartment = "AND sampleTest.departmentid >= @DepartmentId ";
                }
                if (filterAnalytes != null || filterAnalytes.Count() > 0)
                {
                    var analyteIds = filterAnalytes.Select(x => x.AnalyteId).ToArray();
                    if (analyteIds.Count() > 0)
                    {
                        sqlAnalytes = string.Format("AND sampleTest.analyteid IN ({0})", String.Join(",", analyteIds));
                    }
                }
                beginStartDate = DateEx.GetStartOfDay(beginStartDate);
                beginEndDate = DateEx.GetEndOfDay(beginEndDate);

                sqlBeginDate = " AND dbo.ReturnNextBusinessDay(sampleTest.begin_date,timepoints.begindate_days) BETWEEN @BeginStartDate AND @BeginEndDate "; //;DATEADD(day,timepoints.begindate_days, sampleTest.begin_date) BETWEEN @BeginStartDate AND @BeginEndDate ";

                sqlOrderBy = "ORDER BY begin_date";

                string sql = @"
                            SELECT sampleTest.id, sampleTest.parentid,sampleTest.status,sampleTest.sampleid,sampleTest.lab_number,
                            sampleTest.priorityid,sampleTest.typeid,sampleTest.analyteid,sampleTest.testid,
                            sampleTest.departmentid,sampleTest.analystid,sampleTest.method_name,sampleTest.method_number_name,
                            sampleTest.low,sampleTest.high,sampleTest.test_minutes, sampleTest.equipment_minutes,
                            sampleTest.accounting_code,dbo.ReturnNextBusinessDay(sampleTest.begin_date,timepoints.begindate_days) AS begin_date,
                            sampleTest.due_date,sampleTest.has_requirement_code,
                            sampleTest.requirement_code,sampleTest.item_price,sampleTest.rush_charge,sampleTest.bill_groupid,
                            sampleTest.catalogid, sampleTest.methodid, sampleTest.methodnumberid,
                            sampleTest.is_per_analyte, sampleTest.is_price_table,
                            priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                            test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                            analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                            sampleTest.endotoxin_limit,sampleTest.endotoxin_limit_uom, sampleTest.avg_weight, sampleTest.avg_weight_uom,
                            sampleTest.dose_per_hour, sampleTest.dose_per_hour_uom,sampleTest.route_of_administration,
                            sampleTest.articles,sampleTest.is_signed, timepoints.begindate_days, timepoints.timepoint_type,
                            (users.firstname + ' ' + users.lastname) as modifieduser,
                            (users2.firstname + ' ' + users2.lastname) as createduser,
                            sampleTest.modified_by, sampleTest.modified_date, sampleTest.created_by, sampleTest.created_date
                            FROM orders_samples_tests as sampleTest
                            LEFT JOIN  [User] as users ON sampleTest.modified_by = users.UserID
                            LEFT JOIN  [User] as users2 ON sampleTest.created_by = users2.UserID
                            LEFT JOIN  [User] as analyst ON sampleTest.analystid = analyst.UserID
                            LEFT JOIN  list.departments as dpart ON sampleTest.[departmentid] = dpart.[departmentid]
                            LEFT JOIN  list.tests as test ON sampleTest.[testid] = test.[testid]
                            LEFT JOIN  list.analyte as analyte ON sampleTest.[analyteid] = analyte.[analyteid]
                            LEFT JOIN  list.priorities as priorities ON sampleTest.[priorityid] = priorities.[priorityid]
                            LEFT JOIN  orders_samples_tests_timepoints AS timepoints ON timepoints.parentid = sampleTest.id
                            LEFT OUTER JOIN  orders_samples_tests_timepoints_results AS timepointsResults ON timepoints.id = timepointsResults.parentid
                            WHERE ((sampleTest.status = 2 or sampleTest.status = 3) AND sampleTest.delete_date IS NULL AND timepointsResults.result_date IS NULL)
                            ";
                sql += sqlTest;
                sql += sqlAnalyst;
                sql += sqlDepartment;
                sql += sqlBeginDate;
                sql += sqlAnalytes;
                sql += sqlOrderBy;

                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@Status", System.Data.SqlDbType.Int).Value = (int)SampleTestStatus.InProgress;
                dbCommand.Parameters.Add("@TestId", System.Data.SqlDbType.Int).Value = filterItem.TestId ?? 0;
                dbCommand.Parameters.Add("@AnalystId", System.Data.SqlDbType.Int).Value = filterItem.AnalystId ?? 0;
                dbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = filterItem.DepartmentId ?? 0;
                dbCommand.Parameters.Add("@BeginStartDate", System.Data.SqlDbType.DateTime).Value = beginStartDate;
                dbCommand.Parameters.Add("@BeginEndDate", System.Data.SqlDbType.DateTime).Value = beginEndDate;

                dbCommand.CommandText = sql;
                DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);
                foreach (DataRow row in returnDT.Rows)
                {
                    SampleTest sampleTest = new SampleTest();

                    using (CatalogDAO catalogDao = new CatalogDAO())
                    {
                        //sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                    }

                    using (SystemDAO systemDao = new SystemDAO())
                    {
                        //sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                    }

                    resultList.Add(sampleTest);
                }
                returnDT = null;

                return resultList;
            }
            catch
            {
                throw;
            }
        }
예제 #3
0
        private SmartCollection<TimePoint> GetSampleTestTimePoints(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, SampleTest sampleTest, string[] useSql = null)
        {
            string sql = string.Empty;
            SmartCollection<TimePoint> result = new SmartCollection<TimePoint>();
            try
            {
                SmartCollection<BusinessClosedDay> closedDays = new SmartCollection<BusinessClosedDay>();
                using (SystemDAO systeDao = new SystemDAO())
                {
                    closedDays.AddRange(systeDao.GetBusinessClosedDays((DateTime)sampleTest.BeginDate, (DateTime)sampleTest.DueDate));
                }
                sql = useSql != null && useSql[1].Length > 0 ? useSql[1] : @"
                            SELECT
                            timepoints.id, timepoints.parentid,
                            DATEADD(day,timepoints.begindate_days, tests.begin_date) as begin_date,
                            timepoints.timepoint_type,timepoints.status, timepoints.is_on_report,
                            timepoints.report_by,timepoints.report_date, timepoints.report_type, timepoints.begindate_days, timepoints.oosid,
                            timepointDetails.parentid as timepointDetailsParentID,
                            timepointDetails.id as timepointDetailsId, timepointDetails.is_override_record, timepointDetails.limit,
                            timepointDetails.result, timepointDetails.expected_result, timepointDetails.result_date,
                            timepointDetails.is_oos,timepointDetails.created_by, timepointDetails.created_date,
                            timepointDetails.modified_by, timepointDetails.modified_date,
                            (users.firstname + ' ' + users.lastname) as modifieduser,
                            (users1.firstname + ' ' + users1.lastname) as ReportedByUser,
                            (users2.firstname + ' ' + users2.lastname) as createduser
                            FROM orders_samples_tests_timepoints AS timepoints
                            LEFT JOIN orders_samples_tests AS tests ON timepoints.parentid = tests.id
                            LEFT OUTER JOIN orders_samples_tests_timepoints_results AS timepointDetails ON timepoints.id = timepointDetails.parentid
                            LEFT JOIN  [User] AS users ON timepointDetails.modified_by = users.UserID
                            LEFT JOIN  [User] as users1 ON timepoints.report_by = users1.UserID
                            LEFT JOIN  [User] as users2 ON timepointDetails.created_by = users2.UserID
                            WHERE timepoints.parentid = @ParentId
                            ORDER BY timepoints.begindate_days
                            ;";

                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@ParentId", System.Data.SqlDbType.Int).Value = sampleTest.SampleTestId;
                dbCommand.CommandText = sql;
                DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);
                foreach (DataRow row in returnDT.Rows)
                {
                    TimePoint timePoint = new TimePoint();
                    timePoint.Id = Convert.ToInt32(row["Id"]);
                    timePoint.ParentId = Convert.ToInt32(row["ParentId"]);
                    timePoint.BeginDate = AppLib.GetNextOpenBuisnessDay(Convert.ToDateTime(row["begin_date"]), closedDays);
                    timePoint.TimepointType = row["timepoint_type"] != DBNull.Value ? (EnumTimePointType)row["timepoint_type"] : EnumTimePointType.Result;
                    timePoint.IsOnReport = row["is_on_report"] != DBNull.Value ? Convert.ToBoolean(row["is_on_report"]) : false;
                    timePoint.ReportBy = row["report_by"] != DBNull.Value ? (int)row["report_by"] : 0;
                    timePoint.ReportedByUser = row["ReportedByUser"].ToString();
                    timePoint.ReportDate = row["report_date"] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row["report_date"]) : null;
                    timePoint.BeginDateDays = Convert.ToInt32(row["begindate_days"]);
                    timePoint.OosId = row["oosid"] != DBNull.Value ? Convert.ToInt32(row["oosid"]) : 0;
                    timePoint.ResultDetail.Id = row["timepointDetailsId"] != DBNull.Value ? (int?)Convert.ToInt32(row["timepointDetailsId"]) : null;
                    timePoint.ResultDetail.ParentId = row["timepointDetailsParentID"] != DBNull.Value ? (int?)Convert.ToInt32(row["timepointDetailsParentID"]) : null;
                    timePoint.ResultDetail.Limit = row["limit"].ToString();
                    timePoint.ResultDetail.Result = row["result"].ToString();
                    timePoint.ResultDetail.IsOverrideRecord = row["is_override_record"] != DBNull.Value ? Convert.ToBoolean(row["is_override_record"]) : false;
                    timePoint.ResultDetail.IsOos = row["is_oos"] != DBNull.Value ? Convert.ToBoolean(row["is_oos"]) : false;
                    timePoint.ResultDetail.ExpectedResult = row["expected_result"] != DBNull.Value ? (decimal?)Convert.ToDecimal(row["expected_result"]) : null;
                    timePoint.ResultDetail.ResultDate = row["result_date"] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row["result_date"]) : (DateTime?)null;
                    timePoint.ResultDetail.CreatedBy = row["created_by"] != DBNull.Value ? Convert.ToInt32(row["created_by"]) : 0;
                    timePoint.ResultDetail.CreatedUser = row["createduser"].ToString();
                    timePoint.ResultDetail.CreatedDate = row["created_date"] != DBNull.Value ? (DateTime)row["created_date"] : (DateTime)SqlDateTime.Null;
                    timePoint.ResultDetail.ModifiedBy = row["modified_by"] != DBNull.Value ? Convert.ToInt32(row["modified_by"]) : 0;
                    timePoint.ResultDetail.ModifiedUser = row["modifieduser"].ToString();
                    timePoint.ResultDetail.ModifiedDate = row["modified_date"] != DBNull.Value ? (DateTime)row["modified_date"] : (DateTime)SqlDateTime.Null;
                    result.Add(timePoint);
                }
            }
            catch
            {
                throw;
            }
            return result;
        }
예제 #4
0
        private SmartCollection<SampleTest> GetSampleTests(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, int? arlNumber, bool loadCanceled, Identification identification)
        {
            try
            {
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();
                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.CommandText = "uspGetSampleTests";
                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@ARLNumber", System.Data.SqlDbType.Int).Value = arlNumber;
                DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);

                foreach (DataRow row in returnDT.Rows)
                {
                    SampleTest sampleTest = new SampleTest();

                    /*using (CatalogDAO catalogDao = new CatalogDAO())
                    {
                        sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                    }

                    // Do not load predefined notes for canceled tests
                    if (sampleTest.Status != SampleTestStatus.Cancelled)
                    {
                        using (SystemDAO systemDao = new SystemDAO())
                        {
                            //sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                        }
                    }*/

                    sampleTest.SampleTestId = row["SampleTestID"] != DBNull.Value ? (int)row["SampleTestID"] : new Int32();
                    sampleTest.ARLNumber = row["ARLNumber"] != DBNull.Value ? (int)row["ARLNumber"] : new Int32();
                    sampleTest.Status = row["Status"] != DBNull.Value ? (SampleTestStatus)row["Status"] : new Int32();
                    sampleTest.Stage = row["Stage"] != DBNull.Value ? (SampleTestStage)row["Stage"] : new Int32();
                    sampleTest.Type = row["Type"] != DBNull.Value ? (SampleTestType)row["Type"] : new Int32();
                    sampleTest.OriginalSampleTestId = row["OriginalSampleTestID"] != DBNull.Value ? (int?)row["OriginalSampleTestID"] : new Int32();
                    sampleTest.CatalogId = row["CatalogID"] != DBNull.Value ? (int)row["CatalogID"] : new Int32();
                    sampleTest.TestId = row["TestID"] != DBNull.Value ? (int)row["TestID"] : new Int32();
                    sampleTest.TestName = row["TestName"] != DBNull.Value ? row["TestName"].ToString() : null;
                    sampleTest.AnalyteId = row["AnalyteID"] != DBNull.Value ? (int)row["AnalyteID"] : new Int32();
                    sampleTest.AnalyteName = row["AnalyteName"] != DBNull.Value ? row["AnalyteName"].ToString() : null;
                    sampleTest.ControlledYN = row["ControlledYN"] != DBNull.Value ? (bool)row["ControlledYN"] : false;
                    sampleTest.AntibioticYN = row["AntibioticYN"] != DBNull.Value ? (bool)row["AntibioticYN"] : false;
                    if (sampleTest.TestId != null && sampleTest.TestId != 0)
                        sampleTest.Test = new Test() { TestId = sampleTest.TestId, TestName = row["TestName"].ToString()};
                    sampleTest.DepartmentId = row["DepartmentID"] != DBNull.Value ? (int)row["DepartmentId"] : new Int32();
                    sampleTest.DepartmentName = row["DepartmentName"] != DBNull.Value ? row["DepartmentName"].ToString() : null;
                    if (sampleTest.DepartmentId != null && sampleTest.DepartmentId != 0)
                        sampleTest.Department = new Department() { DepartmentId = sampleTest.DepartmentId, DepartmentName = sampleTest.DepartmentName };
                    sampleTest.AnalystId = row["AnalystID"] != DBNull.Value ? (int)row["AnalystID"] : new Int32();
                    sampleTest.AnalystName = row["AnalystName"] != DBNull.Value ? row["AnalystName"].ToString() : null;
                    if (sampleTest.AnalystId != null && sampleTest.AnalystId != 0)
                        sampleTest.Analyst = new User() { UserId = sampleTest.AnalystId, FirstName = sampleTest.AnalystName.IndexOf(' ') > 0 ? sampleTest.AnalystName.Substring(0, sampleTest.AnalystName.IndexOf(' ')) : sampleTest.AnalystName, LastName = sampleTest.AnalystName.IndexOf(' ') > 0 ? sampleTest.AnalystName.Substring(sampleTest.AnalystName.IndexOf(' ') + 1, sampleTest.AnalystName.Length - sampleTest.AnalystName.IndexOf(' ') - 1) : "" };
                    sampleTest.Containers = row["Containers"] != DBNull.Value ? row["Containers"].ToString() : null;
                    sampleTest.MethodId = row["MethodID"] != DBNull.Value ? (int)row["MethodID"] : new Int32();
                    sampleTest.MethodName = row["MethodName"] != DBNull.Value ? row["MethodName"].ToString() : null;
                    sampleTest.MethodNumberId = row["MethodNumberID"] != DBNull.Value ? (int)row["MethodNumberID"] : new Int32();
                    sampleTest.MethodNumberName = row["MethodNumberName"] != DBNull.Value ? row["MethodNumberName"].ToString() : null;
                    sampleTest.OutsourcedYN = row["OutsourcedYN"] != DBNull.Value ? (bool)row["OutsourcedYN"] : false;
                    sampleTest.BasePrice = row["BasePrice"] != DBNull.Value ? (decimal)row["BasePrice"] : new Decimal();
                    if (row["LowSpec"] != DBNull.Value)
                        sampleTest.LowSpec = Convert.ToDecimal(row["LowSpec"]);
                    if (row["HighSpec"] != DBNull.Value)
                        sampleTest.HighSpec = Convert.ToDecimal(row["HighSpec"]);
                    sampleTest.CalculatePercentageExpectedYN = row["CalculatePercentageExpectedYN"] != DBNull.Value ? (bool)row["CalculatePercentageExpectedYN"] : false;
                    sampleTest.OtherSpec = row["OtherSpec"] != DBNull.Value ? row["OtherSpec"].ToString() : null;
                    sampleTest.TestMinutes = row["TestMinutes"] != DBNull.Value ? (short)row["TestMinutes"] : new Int16();
                    sampleTest.EquipmentMinutes = row["EquipmentMinutes"] != DBNull.Value ? (short)row["EquipmentMinutes"] : new Int16();
                    sampleTest.AccountingCode = row["AccountingCode"] != DBNull.Value ? row["AccountingCode"].ToString() : null;
                    sampleTest.Instructions = row["Instructions"] != DBNull.Value ? row["Instructions"].ToString() : null;
                    sampleTest.RequirementYN = row["RequirementYN"] != DBNull.Value ? (bool)row["RequirementYN"] : false;
                    sampleTest.RequirementDescription = row["RequirementDescription"] != DBNull.Value ? row["RequirementDescription"].ToString() : null;
                    sampleTest.EndotoxinLimit = row["EndotoxinLimit"] != DBNull.Value ? (decimal)row["EndotoxinLimit"] : new Decimal();
                    sampleTest.EndotoxinLimitUOM = row["EndotoxinLimitUOM"] != DBNull.Value ? row["EndotoxinLimitUOM"].ToString() : null;
                    sampleTest.AverageWeight = row["AverageWeight"] != DBNull.Value ? (int)row["AverageWeight"] : new Int32();
                    sampleTest.AverageWeightUOM = row["AverageWeightUOM"] != DBNull.Value ? row["AverageWeightUOM"].ToString() : null;
                    sampleTest.DosePerHour = row["DosePerHour"] != DBNull.Value ? (decimal)row["DosePerHour"] : new Decimal();
                    sampleTest.DosePerHourUOM = row["DosePerHourUOM"] != DBNull.Value ? row["DosePerHourUOM"].ToString() : null;
                    sampleTest.RouteOfAdministration = row["RouteOfAdministration"] != DBNull.Value ? row["RouteOfAdministration"].ToString() : null;
                    sampleTest.SignedYN = row["SignedYN"] != DBNull.Value ? (bool)row["SignedYN"] : false;
                    sampleTest.Articles = row["Articles"] != DBNull.Value ? (int)row["Articles"] : new Int32();
                    sampleTest.SignedName = row["SignedName"] != DBNull.Value ? row["SignedName"].ToString() : null;
                    sampleTest.PriorityId = row["PriorityID"] != DBNull.Value ? (int)row["PriorityID"] : new Int32();
                    if (sampleTest.PriorityId != null && sampleTest.PriorityId != 0)
                        using (SystemDAO systemDao = new SystemDAO())
                        {
                            sampleTest.Priority = systemDao.GetPriority(sampleTest.PriorityId);
                        }
                    sampleTest.AdditionalDays = row["AdditionalDays"] != DBNull.Value ? (int)row["AdditionalDays"] : new Int32();
                    sampleTest.PriceAdjustment = row["PriceAdjustment"] != DBNull.Value ? (decimal)row["PriceAdjustment"] : new Decimal();
                    sampleTest.DiscountAllowedYN = row["DiscountAllowedYN"] != DBNull.Value ? (bool)row["DiscountAllowedYN"] : false;
                    sampleTest.BillGroup = row["BillGroup"] != DBNull.Value ? (int)row["BillGroup"] : new Int32();
                    sampleTest.BeginDate = row["BeginDate"] != DBNull.Value ? (DateTime)row["BeginDate"] : new DateTime();
                    sampleTest.DueDate = row["DueDate"] != DBNull.Value ? (DateTime)row["DueDate"] : new DateTime();
                    sampleTest.ApprovedBy = row["ApprovedBy"] != DBNull.Value ? (int)row["ApprovedBy"] : new Int32();
                    sampleTest.ApprovedDate = row["ApprovedDate"] != DBNull.Value ? (DateTime)row["ApprovedDate"] : new DateTime();
                    sampleTest.ModifiedUser = row["ModifiedUser"] != DBNull.Value ? row["ModifiedUser"].ToString() : null;
                    sampleTest.CreatedUser = row["CreatedUser"] != DBNull.Value ? row["CreatedUser"].ToString() : null;
                    sampleTest.CreatedDate = row["CreatedDate"] != DBNull.Value ? (DateTime)row["CreatedDate"] : new DateTime();
                    sampleTest.CreatedBy = row["CreatedBy"] != DBNull.Value ? (int)row["CreatedBy"] : new Int32();
                    sampleTest.ModifiedDate = row["ModifiedDate"] != DBNull.Value ? (DateTime)row["ModifiedDate"] : new DateTime();
                    sampleTest.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? (int)row["ModifiedBy"] : new Int32();

                    sampleTest.Results = GetResultsForSampleTest((int)sampleTest.SampleTestId, identification);

                    resultList.Add(sampleTest);
                }
                returnDT = null;
                return resultList;
            }
            catch
            {
                throw;
            }
        }
예제 #5
0
        private SmartCollection<Sample> GetPendingSubmissions(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, Identification identification)
        {
            try
            {
                SmartCollection<Sample> resultList = new SmartCollection<Sample>();
                SmartCollection<SampleTest> testList = new SmartCollection<SampleTest>();

                User currentUser = new User();
                using (UserDAO userDao = new UserDAO())
                {
                    currentUser = userDao.GetUser(identification.UserId);
                }
                if (currentUser.IsNull() || currentUser.UserId.IsNull())
                    return resultList;

                string sqlDepartment = "AND sampleTest.DepartmentId = @DepartmentId";

                // Check ApproveAll or Administrator rights
                if (AppLib.IsAuthorized(identification, SysLib.GetOptionName(ModuleNames.Samples, ModelNamesEnum.SampleTest, ModuleAction.ApproveAll)))
                {
                    sqlDepartment = "AND sampleTest.DepartmentId >= 0";
                }

                string sql = @"
                            SELECT sampleTest.id, sampleTest.parentid,sampleTest.status,sampleTest.sampleid,sampleTest.lab_number,
                            sampleTest.priorityid,sampleTest.typeid,sampleTest.analyteid,sampleTest.testid,
                            sampleTest.departmentid,sampleTest.analystid,sampleTest.method_name,sampleTest.method_number_name,
                            sampleTest.low,sampleTest.high,sampleTest.test_minutes, sampleTest.equipment_minutes,
                            sampleTest.accounting_code,sampleTest.begin_date,sampleTest.due_date,sampleTest.has_requirement_code,
                            sampleTest.requirement_code,sampleTest.item_price,sampleTest.rush_charge,sampleTest.bill_groupid,
                            sampleTest.catalogid, sampleTest.methodid, sampleTest.methodnumberid,
                            sampleTest.is_per_analyte, sampleTest.is_price_table,
                            priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                            test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                            analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                            sampleTest.endotoxin_limit,sampleTest.endotoxin_limit_uom, sampleTest.avg_weight, sampleTest.avg_weight_uom,
                            sampleTest.dose_per_hour, sampleTest.dose_per_hour_uom,sampleTest.route_of_administration, sampleTest.articles,sampleTest.is_signed,
                            (users.firstname + ' ' + users.lastname) as modifieduser,
                            (users2.firstname + ' ' + users2.lastname) as createduser,
                            sampleTest.modified_by, sampleTest.modified_date, sampleTest.created_by, sampleTest.created_date
                            FROM orders_samples_tests as sampleTest
                            LEFT JOIN  [User] as users ON sampleTest.modified_by = users.UserID
                            LEFT JOIN  [User] as users2 ON sampleTest.created_by = users2.UserID
                            LEFT JOIN  [User] as analyst ON sampleTest.analystid = analyst.UserID
                            LEFT JOIN  list.departments as dpart ON sampleTest.[departmentid] = dpart.[departmentid]
                            LEFT JOIN  list.tests as test ON sampleTest.[testid] = test.[testid]
                            LEFT JOIN  list.analyte as analyte ON sampleTest.[analyteid] = analyte.[analyteid]
                            LEFT JOIN  list.priorities as priorities ON sampleTest.[priorityid] = priorities.[priorityid]
                            WHERE (sampleTest.status = @Status " + sqlDepartment + ") ";
                sql += "AND sampleTest.delete_date IS NULL";

                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@Status", System.Data.SqlDbType.Int).Value = (int)SampleTestStatus.InProgress;
                dbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = currentUser.DepartmentId;
                dbCommand.CommandText = sql;
                DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);
                foreach (DataRow row in returnDT.Rows)
                {
                    SampleTest sampleTest = new SampleTest();

                    using (CatalogDAO catalogDao = new CatalogDAO())
                    {
                        sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                    }

                    using (SystemDAO systemDao = new SystemDAO())
                    {
                        //sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                    }

                    testList.Add(sampleTest);
                }
                returnDT = null;

                if (testList.Count > 0)
                {
                    var sampleIds = testList.Select(x => x.ARLNumber).ToArray();

                    sql = string.Format(@"
                            SELECT sample.id, sample.parentid,sample.sample_type_id,sample.name,sample.lab_number,
                            sample.formulation_id,sample.quote_number,sample.project_number,sample.lot_number,
                            sample.storage_id,sample.dosage_id,dosage.value as dosagevalue,dosage.active as dosageactive, sample.ndc_id, sample.articles,sample.container_type,sample.volume_amount,
                            sample.volume_uom,sample.is_study,sample.is_gmp,sample.compounded_by,sample.compound_date,storage.description as storagedescription, storage.active as storageactive, storage.conditions as storageconditions,
                            (SELECT COUNT(analytes.controlled) FROM orders_samples_analytes AS analytes WHERE analytes.controlled = 'true' and analytes.parentid = sample.id AND analytes.delete_date IS NULL) AS is_cds,
                            (users.firstname + ' ' + users.lastname) as modifieduser, (users2.firstname + ' ' + users2.lastname) as createduser,
                            sample.modified_by, sample.modified_date, sample.created_by, sample.created_date
                            FROM orders_samples as sample
                            LEFT JOIN [User] as users ON sample.modified_by = users.UserID
                            LEFT JOIN [User] as users2 ON sample.created_by = users2.UserID
                            LEFT JOIN list.dosagetype as dosage ON sample.dosage_id = dosage.dosageid
                            LEFT JOIN list.storage as storage ON sample.storage_id = storage.storageid
                            WHERE sample.id IN ({0}) AND sample.delete_date IS NULL
                            ;", String.Join(",", sampleIds));

                    dbCommand.Parameters.Clear();
                    dbCommand.CommandText = sql;
                    returnDT = dbConnection.ExecuteQuery(dbCommand);
                    foreach (DataRow row in returnDT.Rows)
                    {
                        Sample sample = new Sample();

                        resultList.Add(sample);
                    }
                    foreach (Sample sampleItem in resultList)
                    {
                        sampleItem.SampleTests.AddRange(testList.Where(x => x.ARLNumber == sampleItem.ARLNumber).Select(s => s));
                    }
                }

                returnDT = null;
                return resultList;
            }
            catch
            {
                throw;
            }
        }
예제 #6
0
        private SmartCollection<SampleTest> GetPendingFinalizations(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, Identification identification)
        {
            try
            {
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();

                User currentUser = new User();
                using (UserDAO userDao = new UserDAO())
                {
                    currentUser = userDao.GetUser(identification.UserId);
                }
                if (currentUser.IsNull() || currentUser.UserId.IsNull())
                    return resultList;

                string sqlDepartment = "AND sampleTest.DepartmentId = @DepartmentId";

                // Check ApproveAll or Administrator rights
                if (AppLib.IsAuthorized(identification, SysLib.GetOptionName(ModuleNames.Samples, ModelNamesEnum.SampleTest, ModuleAction.FinalizeAll)))
                {
                    sqlDepartment = "AND sampleTest.DepartmentId >= 0";
                }

                string sql = @"
                            SELECT sampleTest.id, sampleTest.parentid,sampleTest.status,sampleTest.sampleid,sampleTest.lab_number,
                            sampleTest.priorityid,sampleTest.typeid,sampleTest.analyteid,sampleTest.testid,
                            sampleTest.departmentid,sampleTest.analystid,sampleTest.method_name,sampleTest.method_number_name,
                            sampleTest.low,sampleTest.high,sampleTest.test_minutes, sampleTest.equipment_minutes,
                            sampleTest.accounting_code,sampleTest.begin_date,sampleTest.due_date,sampleTest.has_requirement_code,
                            sampleTest.requirement_code,sampleTest.item_price,sampleTest.rush_charge,sampleTest.bill_groupid,
                            sampleTest.catalogid, sampleTest.methodid, sampleTest.methodnumberid,
                            sampleTest.is_per_analyte, sampleTest.is_price_table,
                            priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                            test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                            analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                            sampleTest.endotoxin_limit,sampleTest.endotoxin_limit_uom, sampleTest.avg_weight, sampleTest.avg_weight_uom,
                            sampleTest.dose_per_hour, sampleTest.dose_per_hour_uom,sampleTest.route_of_administration, sampleTest.articles,sampleTest.is_signed,
                            (users.firstname + ' ' + users.lastname) as modifieduser,
                            (users2.firstname + ' ' + users2.lastname) as createduser,
                            sampleTest.modified_by, sampleTest.modified_date, sampleTest.created_by, sampleTest.created_date
                            FROM orders_samples_tests as sampleTest
                            LEFT JOIN  [User] as users ON sampleTest.modified_by = users.UserID
                            LEFT JOIN  [User] as users2 ON sampleTest.created_by = users2.UserID
                            LEFT JOIN  [User] as analyst ON sampleTest.analystid = analyst.UserID
                            LEFT JOIN  list.departments as dpart ON sampleTest.[departmentid] = dpart.[departmentid]
                            LEFT JOIN  list.tests as test ON sampleTest.[testid] = test.[testid]
                            LEFT JOIN  list.analyte as analyte ON sampleTest.[analyteid] = analyte.[analyteid]
                            LEFT JOIN  list.priorities as priorities ON sampleTest.[priorityid] = priorities.[priorityid]
                            WHERE (sampleTest.status = @Status " + sqlDepartment + ") ";
                sql += "AND sampleTest.delete_date IS NULL";

                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@Status", System.Data.SqlDbType.Int).Value = (int)SampleTestStatus.InProgress;
                dbCommand.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = currentUser.DepartmentId;
                dbCommand.CommandText = sql;
                DataTable returnDT = dbConnection.ExecuteQuery(dbCommand);
                foreach (DataRow row in returnDT.Rows)
                {
                    SampleTest sampleTest = new SampleTest();

                    resultList.Add(sampleTest);
                }
                returnDT = null;
                return resultList;
            }
            catch
            {
                throw;
            }
        }
예제 #7
0
        public SmartCollection<SampleTest> SearchResultSampleTests(string searchString, Identification identification)
        {
            try
            {
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();
                string containerSearch = string.Empty;
                int? labNumber = null;
                int? sampleTestId = null;
                try
                {
                    if (searchString.Contains("-"))
                    {
                        containerSearch = searchString;
                    }
                    else if (searchString.Contains(","))
                    {
                        char[] charSeparators = new char[] { ',' };
                        string[] sepString = searchString.Split(charSeparators, StringSplitOptions.None);
                        labNumber = Convert.ToInt32(sepString[0].Trim());
                        sampleTestId = Convert.ToInt32(sepString[1].Trim());
                    }
                    else
                    {
                        labNumber = Convert.ToInt32(searchString.Trim());
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Search value is an invalid format");
                }

                using (DbConnection = new MsSqlPersistence(DbConnectionSettings))
                {
                    if (DbConnection.IsConnected())
                    {
                        using (DbCommand)
                        {
                            string sql =
                                @"
                                    SELECT DISTINCT
                                    sampleTests.id,timepoints.id as timePointId, sampleTests.parentid,sampleTests.status,sampleTests.sampleid,sampleTests.lab_number,
                                    sampleTests.priorityid,sampleTests.typeid,sampleTests.analyteid,sampleTests.testid,
                                    sampleTests.departmentid,sampleTests.analystid,sampleTests.method_name,sampleTests.method_number_name,
                                    sampleTests.low,sampleTests.high,sampleTests.test_minutes, sampleTests.equipment_minutes,
                                    sampleTests.accounting_code,dbo.ReturnNextBusinessDay(sampleTests.begin_date,timepoints.begindate_days) AS begin_date,
                                    sampleTests.due_date,sampleTests.has_requirement_code,
                                    sampleTests.requirement_code,sampleTests.item_price,sampleTests.rush_charge,sampleTests.bill_groupid,
                                    sampleTests.catalogid, sampleTests.methodid, sampleTests.methodnumberid,
                                    sampleTests.is_per_analyte, sampleTests.is_price_table,
                                    priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                                    test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                                    analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                                    sampleTests.endotoxin_limit,sampleTests.endotoxin_limit_uom, sampleTests.avg_weight, sampleTests.avg_weight_uom,
                                    sampleTests.dose_per_hour, sampleTests.dose_per_hour_uom,sampleTests.route_of_administration,
                                    sampleTests.articles,sampleTests.is_signed, timepoints.begindate_days,
                                    (users.firstname + ' ' + users.lastname) as modifieduser,
                                    (users2.firstname + ' ' + users2.lastname) as createduser,
                                    sampleTests.modified_by, sampleTests.modified_date, sampleTests.created_by, sampleTests.created_date,
                                    timepoints.timepoint_type
                                    FROM orders_samples_tests AS sampleTests
                                    RIGHT JOIN  orders_samples_tests_timepoints AS timepoints ON timepoints.id = (
                                        SELECT TOP 1
                                        timepoints.id
                                        FROM orders_samples_tests_timepoints AS timepoints
                                        LEFT OUTER JOIN  orders_samples_tests_timepoints_results AS timepointsResults ON timepoints.id = timepointsResults.parentid
                                        WHERE
                                        timepointsResults.result_date IS NULL AND timepoints.parentid = sampleTests.id
                                        ORDER BY timepoints.begindate_days
                                    )
                                    LEFT JOIN orders_samples_tests_timepoints_oos AS oos ON oos.id = timepoints.oosid AND oos.is_testing_complete = 'true'  -- Continue Testing
                                    LEFT JOIN  [User] as users ON sampleTests.modified_by = users.UserID
                                    LEFT JOIN  [User] as users2 ON sampleTests.created_by = users2.UserID
                                    LEFT JOIN  [User] as analyst ON sampleTests.analystid = analyst.UserID
                                    LEFT JOIN  list.departments as dpart ON sampleTests.[departmentid] = dpart.[departmentid]
                                    LEFT JOIN  list.tests as test ON sampleTests.[testid] = test.[testid]
                                    LEFT JOIN  list.analyte as analyte ON sampleTests.[analyteid] = analyte.[analyteid]
                                    LEFT JOIN  list.priorities as priorities ON sampleTests.[priorityid] = priorities.[priorityid]
                                    LEFT JOIN orders_samples_tests_containers AS containers ON containers.parentid = sampleTests.id
                                    WHERE ((sampleTests.status = 2 OR sampleTests.status = 3)  AND sampleTests.delete_date IS NULL AND oos.id IS NULL)
                                    ";

                            // Maybe Limit Results by Analyst and/or Department

                            DbCommand.Parameters.Clear();

                            if (!String.IsNullOrWhiteSpace(containerSearch))
                            {
                                sql += "AND containers.containerid = @ContainerId ";
                                DbCommand.Parameters.Add("@ContainerId", System.Data.SqlDbType.VarChar, 100).Value = containerSearch;
                            }
                            else if (labNumber != null && sampleTestId != null)
                            {
                                sql += "AND sampleTests.lab_number = @LabNumber AND sampleTests.id = @SampleTestId ";
                                DbCommand.Parameters.Add("@LabNumber", System.Data.SqlDbType.Int).Value = labNumber;
                                DbCommand.Parameters.Add("@SampleTestId", System.Data.SqlDbType.Int).Value = sampleTestId;
                            }
                            else
                            {
                                sql += "AND sampleTests.lab_number = @LabNumber ";
                                DbCommand.Parameters.Add("@LabNumber", System.Data.SqlDbType.Int).Value = labNumber;
                            }

                            sql += " ORDER BY sampleTests.id";

                            DbCommand.CommandText = sql;
                            //DbCommand.Parameters.Add("@Status", System.Data.SqlDbType.Int).Value = (int)SampleTestStatus.Approved;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            foreach (DataRow row in returnDT.Rows)
                            {
                                SampleTest sampleTest = new SampleTest();

                                using (CatalogDAO catalogDao = new CatalogDAO())
                                {
                                    //sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                                }

                                using (SystemDAO systemDao = new SystemDAO())
                                {
                                    //sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                                }

                                resultList.Add(sampleTest);
                            }
                            returnDT = null;
                        }
                        return resultList;
                    }
                    else
                    {
                        throw new Exception("Unable to Connect");
                    }
                }
            }
            catch
            {
                throw;
            }
        }
예제 #8
0
        public int SaveOrderSampleTestContainers(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, SampleTest sampleTest, Sample sample, int userId, List<int> containerList)
        {
            try
            {
                int returnValue = 0;
                dbCommand.CommandType = CommandType.StoredProcedure;
                dbCommand.CommandText = "uspRemoveSampleTestContainers";
                dbCommand.Parameters.Clear();
                dbCommand.Parameters.Add("@SampleTestId", System.Data.SqlDbType.Int).Value = sampleTest.SampleTestId;
                dbConnection.ExecuteCommand(dbCommand);

                foreach (int container in containerList)
                {
                    dbCommand.CommandText = "uspRemoveSampleTestContainers";
                    dbCommand.Parameters.Clear();

                    dbCommand.Parameters.Add("@SampleTestId", System.Data.SqlDbType.Int).Value = sampleTest.SampleTestId;
                    dbCommand.Parameters.Add("@ContainerNumber", System.Data.SqlDbType.Text, 100).Value = container;
                    dbCommand.Parameters.Add("@Label", System.Data.SqlDbType.NVarChar, 50).Value = sample.ARLNumber + "-" + container;
                    returnValue += dbConnection.ExecuteCommand(dbCommand);
                }
                return returnValue;
            }
            catch
            {
                throw;
            }
        }
예제 #9
0
        public SmartCollection<SampleTest> GetWorkOrders(List<string> recordList, Identification identification)
        {
            try
            {
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();
                using (DbConnection = new MsSqlPersistence(DbConnectionSettings))
                {
                    if (DbConnection.IsConnected())
                    {
                        using (DbCommand)
                        {
                            string sqlSampleTests = string.Format("AND sampleTest.id IN ({0}) ", String.Join(",", recordList));
                            string sql = @"
                            SELECT sampleTest.id, sampleTest.parentid,sampleTest.status,sampleTest.sampleid,sampleTest.lab_number,
                            sampleTest.priorityid,sampleTest.typeid,sampleTest.analyteid,sampleTest.testid,
                            sampleTest.departmentid,sampleTest.analystid,sampleTest.method_name,sampleTest.method_number_name,
                            sampleTest.low,sampleTest.high,sampleTest.test_minutes, sampleTest.equipment_minutes,
                            sampleTest.accounting_code,sampleTest.begin_date,sampleTest.due_date,sampleTest.has_requirement_code,
                            sampleTest.requirement_code,sampleTest.item_price,sampleTest.rush_charge,sampleTest.bill_groupid,
                            sampleTest.catalogid, sampleTest.methodid, sampleTest.methodnumberid,
                            sampleTest.is_per_analyte, sampleTest.is_price_table,sampleTest.notes,sampleTest.is_discount_allowed,
                            priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                            test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                            analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                            sampleTest.endotoxin_limit,sampleTest.endotoxin_limit_uom, sampleTest.avg_weight, sampleTest.avg_weight_uom,
                            sampleTest.dose_per_hour, sampleTest.dose_per_hour_uom,sampleTest.route_of_administration, sampleTest.articles,sampleTest.is_signed,
                            orders_samples.status as sample_status,
                            (users.firstname + ' ' + users.lastname) as modifieduser,
                            (users2.firstname + ' ' + users2.lastname) as createduser,
                            sampleTest.modified_by, sampleTest.modified_date, sampleTest.created_by, sampleTest.created_date
                            FROM orders_samples_tests as sampleTest
                            LEFT JOIN  orders_samples ON sampleTest.sampleid = orders_samples.id
                            LEFT JOIN  [User] as users ON sampleTest.modified_by = users.UserID
                            LEFT JOIN  [User] as users2 ON sampleTest.created_by = users2.UserID
                            LEFT JOIN  [User] as analyst ON sampleTest.analystid = analyst.UserID
                            LEFT JOIN  list.departments as dpart ON sampleTest.[departmentid] = dpart.[departmentid]
                            LEFT JOIN  list.tests as test ON sampleTest.[testid] = test.[testid]
                            LEFT JOIN  list.analyte as analyte ON sampleTest.[analyteid] = analyte.[analyteid]
                            LEFT JOIN  list.priorities as priorities ON sampleTest.[priorityid] = priorities.[priorityid]
                            WHERE sampleTest.delete_date IS NULL ";
                            sql += sqlSampleTests;
                            sql += "ORDER BY sampleTest.id DESC";

                            DbCommand.CommandText = sql;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            foreach (DataRow row in returnDT.Rows)
                            {
                                SampleTest sampleTest = new SampleTest();

                                using (CatalogDAO catalogDao = new CatalogDAO())
                                {
                                    sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                                }

                                // Do not load predefined notes for canceled tests
                                if (sampleTest.Status != SampleTestStatus.Cancelled)
                                {
                                    using (SystemDAO systemDao = new SystemDAO())
                                    {
                                        //sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                                    }
                                }
                                resultList.Add(sampleTest);
                            }

                            returnDT = null;
                        }
                    }
                    else
                    {
                        throw new Exception("Unable to Connect");
                    }
                }
                return resultList;
            }
            catch
            {
                throw;
            }
        }
예제 #10
0
 public SmartCollection<TimePoint> GetSampleTestTimePoints(SampleTest sampleTest)
 {
     try
     {
         using (DbConnection = new MsSqlPersistence(DbConnectionSettings))
         {
             if (DbConnection.IsConnected())
             {
                 using (DbCommand)
                 {
                     return this.GetSampleTestTimePoints(ref dbConnection, ref dbCommand, sampleTest);
                 }
             }
             else
             {
                 throw new Exception("Unable to Connect");
             }
         }
     }
     catch
     {
         throw;
     }
 }
예제 #11
0
        public SmartCollection<SampleTest> GetSampleTestsResultsList(SmartCollection<SampleTest> list, Identification identification)
        {
            try
            {
                string sql = string.Empty;
                SmartCollection<SampleTest> resultList = new SmartCollection<SampleTest>();
                using (DbConnection = new MsSqlPersistence(DbConnectionSettings))
                {
                    if (DbConnection.IsConnected())
                    {
                        using (DbCommand)
                        {
                            foreach (SampleTest sampleTestItem in list)
                            {
                                DbCommand.Parameters.Clear();
                                sql =
                                    @"
                                    SELECT
                                    sampleTests.id,timepoints.id as timePointId, sampleTests.parentid,sampleTests.status,sampleTests.sampleid,sampleTests.lab_number,
                                    sampleTests.priorityid,sampleTests.typeid,sampleTests.analyteid,sampleTests.testid,
                                    sampleTests.departmentid,sampleTests.analystid,sampleTests.method_name,sampleTests.method_number_name,
                                    sampleTests.low,sampleTests.high,sampleTests.test_minutes, sampleTests.equipment_minutes,
                                    sampleTests.accounting_code,dbo.ReturnNextBusinessDay(sampleTests.begin_date,timepoints.begindate_days) AS begin_date,
                                    sampleTests.due_date,sampleTests.has_requirement_code,
                                    sampleTests.requirement_code,sampleTests.item_price,sampleTests.rush_charge,sampleTests.bill_groupid,
                                    sampleTests.catalogid, sampleTests.methodid, sampleTests.methodnumberid,
                                    sampleTests.is_per_analyte, sampleTests.is_price_table,
                                    priorities.value as priorityname, priorities.active as priorityactive,dpart.department_name,dpart.result_template,
                                    test.testname,test.active as testactive,analyte.analytename,analyte.controlled,
                                    analyte.active as analyteactive,analyst.firstname, analyst.lastname,
                                    sampleTests.endotoxin_limit,sampleTests.endotoxin_limit_uom, sampleTests.avg_weight, sampleTests.avg_weight_uom,
                                    sampleTests.dose_per_hour, sampleTests.dose_per_hour_uom,sampleTests.route_of_administration,
                                    sampleTests.articles,sampleTests.is_signed, timepoints.begindate_days,
                                    (users.firstname + ' ' + users.lastname) as modifieduser,
                                    (users2.firstname + ' ' + users2.lastname) as createduser,
                                    sampleTests.modified_by, sampleTests.modified_date, sampleTests.created_by, sampleTests.created_date,
                                    timepoints.timepoint_type
                                    FROM orders_samples_tests AS sampleTests
                                    RIGHT JOIN  orders_samples_tests_timepoints AS timepoints ON timepoints.id = (
                                        SELECT TOP 1
                                        timepoints.id
                                        FROM orders_samples_tests_timepoints AS timepoints
                                        LEFT OUTER JOIN  orders_samples_tests_timepoints_results AS timepointsResults ON timepoints.id = timepointsResults.parentid
                                        WHERE
                                        timepointsResults.result_date IS NULL AND timepoints.parentid = sampleTests.id
                                        ORDER BY timepoints.begindate_days
                                    )
                                    LEFT JOIN orders_samples_tests_timepoints_oos AS oos ON oos.id = timepoints.oosid AND oos.is_testing_complete = 'true'  -- Continue Testing
                                    LEFT JOIN orders_samples_tests_containers AS containers ON containers.parentid = sampleTests.id
                                    LEFT JOIN  [User] as users ON sampleTests.modified_by = users.UserID
                                    LEFT JOIN  [User] as users2 ON sampleTests.created_by = users2.UserID
                                    LEFT JOIN  [User] as analyst ON sampleTests.analystid = analyst.UserID
                                    LEFT JOIN  list.departments as dpart ON sampleTests.[departmentid] = dpart.[departmentid]
                                    LEFT JOIN  list.tests as test ON sampleTests.[testid] = test.[testid]
                                    LEFT JOIN  list.analyte as analyte ON sampleTests.[analyteid] = analyte.[analyteid]
                                    LEFT JOIN  list.priorities as priorities ON sampleTests.[priorityid] = priorities.[priorityid]
                                    WHERE ((sampleTests.status = 2 OR sampleTests.status = 3)  AND sampleTests.delete_date IS NULL AND oos.id IS NULL)
                                    AND sampleTests.lab_number = @LabNumber AND sampleTests.id = @SampleTestId
                                    ORDER BY sampleTests.id
                                    ";

                                // Maybe Limit Results by Analyst and/or Department

                                DbCommand.CommandText = sql;
                                DbCommand.Parameters.Add("@LabNumber", System.Data.SqlDbType.Int).Value = sampleTestItem.ARLNumber;
                                DbCommand.Parameters.Add("@SampleTestId", System.Data.SqlDbType.Int).Value = sampleTestItem.SampleTestId;
                                DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                                foreach (DataRow row in returnDT.Rows)
                                {
                                    SampleTest sampleTest = new SampleTest();
                                    //sampleTest.Sample = this.GetSample(ref dbConnection, ref dbCommand, sampleTest.SampleId);

                                    //using (CatalogDAO catalogDao = new CatalogDAO()) {
                                    //    sampleTest.CatalogItem = catalogDao.GetCatalogItem((int)sampleTest.CatalogId, identification);
                                    //}

                                    //using (SystemDAO systemDao = new SystemDAO()) {
                                    //    sampleTest.CatalogNotes = systemDao.ReturnNoteItems(sampleTest.CatalogItem);
                                    //}

                                    resultList.Add(sampleTest);
                                    returnDT = null;
                                }
                            }
                        }
                        return resultList;
                    }
                    else
                    {
                        throw new Exception("Unable to Connect");
                    }
                }
            }
            catch
            {
                throw;
            }
        }
예제 #12
0
 public void Cancel()
 {
     this.SelectedResult = null;
     this.TryClose();
 }