public IAsyncResult BeginReturnToOos(TimePoint timePoint, SampleNote note, Identification identification, AsyncCallback callback, object state) { logger.Log(LogLevel.Trace, AppLib.GetCaller(logger)); identification.UserId = AppLib.VerifyToken(identification.Token); if (identification.UserId <= 0) { throw new FaultException<ServiceFault>(new ServiceFault("Invalid Authentication", "Authorization"), new FaultReason("Unauthorized")); } var task = Task<int>.Factory.StartNew(process => DoReturnToOos(timePoint, note, identification), state); return task.ContinueWith(res => callback(task)); }
public int DoReturnToOos(TimePoint timePoint, SampleNote note, Identification identification) { logger.Log(LogLevel.Trace, AppLib.GetCaller(logger)); using (SampleDAO dao = new SampleDAO()) { return dao.ReturnToOos(timePoint, note, identification); } }
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; }
private TimePoint GetSampleTestTimePoint(ref MsSqlPersistence dbConnection, ref SqlCommand dbCommand, int id, DateTime beginDate) { TimePoint result = new TimePoint(); try { string sql = @" SELECT timepoints.id, timepoints.parentid, 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, (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 users2 ON timepointDetails.created_by = users2.UserID WHERE timepoints.id = @Id ORDER BY timepoints.begindate_days ;"; dbCommand.Parameters.Clear(); dbCommand.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = id; dbCommand.CommandText = sql; DataTable returnDT = dbConnection.ExecuteQuery(dbCommand); if (returnDT.Rows.Count == 1) { DataRow row = returnDT.Rows[0]; result.Id = Convert.ToInt32(row["Id"]); result.ParentId = Convert.ToInt32(row["ParentId"]); result.BeginDate = beginDate; result.TimepointType = row["timepoint_type"] != DBNull.Value ? (EnumTimePointType)row["timepoint_type"] : EnumTimePointType.Result; result.IsOnReport = row["is_on_report"] != DBNull.Value ? Convert.ToBoolean(row["is_on_report"]) : false; result.ReportBy = row["report_by"] != DBNull.Value ? (int)row["report_by"] : 0; result.ReportDate = row["report_date"] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row["report_date"]) : (DateTime?)null; result.BeginDateDays = Convert.ToInt32(row["begindate_days"]); result.OosId = row["oosid"] != DBNull.Value ? Convert.ToInt32(row["oosid"]) : 0; result.ResultDetail.Id = row["timepointDetailsId"] != DBNull.Value ? (int?)Convert.ToInt32(row["timepointDetailsId"]) : null; result.ResultDetail.ParentId = row["timepointDetailsParentID"] != DBNull.Value ? (int?)Convert.ToInt32(row["timepointDetailsParentID"]) : null; result.ResultDetail.Limit = row["limit"].ToString(); result.ResultDetail.Result = row["result"].ToString(); result.ResultDetail.IsOos = row["is_oos"] != DBNull.Value ? Convert.ToBoolean(row["is_oos"]) : false; result.ResultDetail.IsOverrideRecord = row["is_override_record"] != DBNull.Value ? Convert.ToBoolean(row["is_override_record"]) : false; result.ResultDetail.ExpectedResult = row["expected_result"] != DBNull.Value ? (decimal?)Convert.ToDecimal(row["expected_result"]) : null; result.ResultDetail.ResultDate = row["result_date"] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row["result_date"]) : (DateTime?)null; result.ResultDetail.CreatedBy = row["created_by"] != DBNull.Value ? Convert.ToInt32(row["created_by"]) : 0; result.ResultDetail.CreatedUser = row["createduser"].ToString(); result.ResultDetail.CreatedDate = row["created_date"] != DBNull.Value ? (DateTime)row["created_date"] : (DateTime)SqlDateTime.Null; result.ResultDetail.ModifiedBy = row["modified_by"] != DBNull.Value ? Convert.ToInt32(row["modified_by"]) : 0; result.ResultDetail.ModifiedUser = row["modifieduser"].ToString(); result.ResultDetail.ModifiedDate = row["modified_date"] != DBNull.Value ? (DateTime)row["modified_date"] : (DateTime)SqlDateTime.Null; } return result; } catch { throw; } }
public int ReturnToOos(TimePoint timePoint, SampleNote note, Identification identification) { int rowsAffected; using (DbConnection = new MsSqlPersistence(DbConnectionSettings, true)) { try { if (DbConnection.IsConnected()) { using (DbCommand) { SystemDAO.SaveChangeAudit<TimePoint>(ref dbConnection, ref dbCommand, "Return to OOS #:" + timePoint.OosId.ToString(), "Status", "Approved", "Pending Investigation", ModuleNames.Samples, timePoint.ParentId, timePoint.Pk, identification.UserId); this.SaveSampleNote(ref dbConnection, ref dbCommand, ref note, (int)timePoint.ParentId, identification); string sql = string.Empty; sql = "UPDATE orders_samples_tests_timepoints_oos " + "SET status = @Status " + "WHERE id = @ID"; DbCommand.Parameters.Clear(); DbCommand.Parameters.Add("@ID", System.Data.SqlDbType.Int).Value = timePoint.OosId; DbCommand.Parameters.Add("@Status", System.Data.SqlDbType.Int).Value = (int)EnumOosStatus.Open; DbCommand.CommandText = sql; rowsAffected = DbConnection.ExecuteCommand(DbCommand); OrderSampleTestsSetStatus(ref dbConnection, ref dbCommand, (int)timePoint.ParentId, identification); } } else { throw new Exception("Unable to Connect"); } return rowsAffected; } catch { throw; } } }
public ReturnToOosRequest(TimePoint timePoint, ClientNote requiredNote) { this.timePoint = timePoint; this.requiredNote = requiredNote; }