public int UpdateCausation(decimal incidentID) { int status = 0; using (PSsqmEntities ctx = new PSsqmEntities()) { status = ctx.ExecuteStoreCommand("DELETE FROM INCFORM_CAUSATION WHERE INCIDENT_ID = " + incidentID.ToString()); if (!string.IsNullOrEmpty(ddlCausation.SelectedValue)) { INCFORM_CAUSATION causation = new INCFORM_CAUSATION(); causation.INCIDENT_ID = incidentID; causation.CAUSEATION_CD = ddlCausation.SelectedValue; causation.TEAM_LIST = tbTeam.Text.Trim(); causation.LAST_UPD_BY = SessionManager.UserContext.UserName(); causation.LAST_UPD_DT = WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ); ctx.AddToINCFORM_CAUSATION(causation); status = ctx.SaveChanges(); EHSIncidentMgr.UpdateIncidentStatus(incidentID, IncidentStepStatus.rootcauseComplete, WebSiteCommon.LocalTime(DateTime.UtcNow, IncidentLocationTZ)); } else { } } return(status); }
public AlertData() { incidentDate = "N/A"; incidentTime = "N/A"; incidentLocation = "N/A"; locationNLS = "en"; incidentDept = "N/A"; incidentNumber = "N/A"; incidentType = "N/A"; incidentDescription = "N/A"; detectPerson = null; involvedPerson = null; supervisorPerson = null; incident = null; answerList = new List <INCIDENT_ANSWER>(); containList = new List <INCFORM_CONTAIN>(); root5YList = new List <INCFORM_ROOT5Y>(); causation = null; actionList = new List <TASK_STATUS>(); approvalList = new List <EHSIncidentApproval>(); }
public void BindCausation(INCIDENT incident) { try { if (SessionManager.SessionContext != null) { // do we really need to do this on user controls ??? String selectedLanguage = SessionManager.UserContext.Language.NLS_LANGUAGE; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); base.FrameworkInitialize(); } pnlCausation.Visible = true; if (PageMode == PageUseMode.ViewOnly) { divTitle.Visible = true; lblFormTitle.Text = Resources.LocalizedText.Causation; } if (incident != null) { lblIncidentDesc.Text = incident.DESCRIPTION; IncidentId = incident.INCIDENT_ID; } if (incident == null || incident.INCFORM_ROOT5Y == null || incident.INCFORM_ROOT5Y.Count == 0) { lblNoneRootCause.Visible = true; divCausation.Visible = btnSave.Visible = false; } else { List <INCFORM_ROOT5Y> rootCauseList = new List <INCFORM_ROOT5Y>(); rootCauseList = EHSIncidentMgr.FormatRootCauseList(incident, incident.INCFORM_ROOT5Y.ToList()); lblNoneRootCause.Visible = false; divCausation.Visible = true; rptRootCause.DataSource = rootCauseList; rptRootCause.DataBind(); INCFORM_CAUSATION causation = incident.INCFORM_CAUSATION == null || incident.INCFORM_CAUSATION.Count == 0 ? null : incident.INCFORM_CAUSATION.ElementAt(0); ddlCausation.Items.Clear(); ddlCausation.Items.Add(new RadComboBoxItem("", "")); var ListCausation = EHSMetaDataMgr.SelectMetaDataList("INJURY_CAUSE").ToList(); if (IncidentId > max_NewIncident) { ListCausation = ListCausation.Where(p => p.Value.Contains("NEW_IC_")).ToList(); } else { ListCausation = ListCausation.Where(p => !p.Value.Contains("NEW_IC_")).ToList(); } foreach (EHSMetaData xlat in ListCausation) { ddlCausation.Items.Add(new Telerik.Web.UI.RadComboBoxItem(xlat.TextLong, xlat.Value)); } if (SessionManager.GetUserSetting("EHS", "CAUSATION_ADD_FIELDS") != null) { if (SessionManager.GetUserSetting("EHS", "CAUSATION_ADD_FIELDS").VALUE.Contains("team")) { divTeam.Visible = true; } } if (causation != null) { if (ddlCausation.FindItemByValue(causation.CAUSEATION_CD) != null) { ddlCausation.SelectedValue = causation.CAUSEATION_CD; } tbTeam.Text = causation.TEAM_LIST; } btnSave.Visible = PageMode == PageUseMode.ViewOnly ? false : EHSIncidentMgr.CanUpdateIncident(null, true, SysPriv.action, incident.INCFORM_LAST_STEP_COMPLETED); } } catch { } }
protected void btnConversion_Click(object sender, EventArgs e) { int status = 0; INCIDENT_ANSWER answer = null; List <XLAT> xlatList = SQMBasePage.SelectXLATList(new string[6] { "SHIFT", "INJURY_CAUSE", "INJURY_TYPE", "INJURY_PART", "INJURY_TENURE", "IQ_10" }); foreach (EHSIncidentData eda in HSCalcs().ehsCtl.IncidentHst.Where(i => i.Incident.INCFORM_LAST_STEP_COMPLETED < 1 && i.Incident.INCIDENT_ID > 0)) { INCIDENT incident = (from i in entities.INCIDENT where i.INCIDENT_ID == eda.Incident.INCIDENT_ID select i).SingleOrDefault(); incident.INCIDENT_ANSWER.Load(); // clear any prior conversion reecords string delCmd = " = " + incident.INCIDENT_ID.ToString(); status = entities.ExecuteStoreCommand("DELETE FROM TASK_STATUS WHERE RECORD_TYPE = 40 AND RECORD_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_LOSTTIME_HIST WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_CONTAIN WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_ACTION WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_ROOT5Y WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_CAUSATION WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_APPROVAL WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_WITNESS WHERE INCIDENT_ID" + delCmd); status = entities.ExecuteStoreCommand("DELETE FROM INCFORM_INJURYILLNESS WHERE INCIDENT_ID" + delCmd); EHSIncidentTypeId issueType = (EHSIncidentTypeId)incident.ISSUE_TYPE_ID; try { switch (issueType) { case EHSIncidentTypeId.PropertyDamage: case EHSIncidentTypeId.PowerOutage: case EHSIncidentTypeId.Fire: case EHSIncidentTypeId.Explosion: case EHSIncidentTypeId.ImsAudit: case EHSIncidentTypeId.RegulatoryContact: case EHSIncidentTypeId.FireSystemImpairment: case EHSIncidentTypeId.SpillRelease: case EHSIncidentTypeId.EhsWalk: case EHSIncidentTypeId.NearMiss: case EHSIncidentTypeId.InjuryIllness: incident.INCFORM_LAST_STEP_COMPLETED = 100; // assume new status answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 69).FirstOrDefault(); // containment if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { incident.INCFORM_LAST_STEP_COMPLETED = 110; // containment INCFORM_CONTAIN contain = new INCFORM_CONTAIN(); contain.INCIDENT_ID = incident.INCIDENT_ID; contain.ITEM_SEQ = 1; contain.ITEM_DESCRIPTION = answer.ANSWER_VALUE; contain.ASSIGNED_PERSON_ID = incident.CREATE_PERSON; contain.START_DATE = contain.COMPLETION_DATE = incident.CREATE_DT; contain.IsCompleted = true; contain.LAST_UPD_BY = SessionManager.UserContext.UserName(); contain.LAST_UPD_DT = DateTime.UtcNow; entities.AddToINCFORM_CONTAIN(contain); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 24).FirstOrDefault(); // root cause if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { incident.INCFORM_LAST_STEP_COMPLETED = 120; // root cause INCFORM_ROOT5Y rootc = new INCFORM_ROOT5Y(); rootc.INCIDENT_ID = incident.INCIDENT_ID; rootc.ITEM_SEQ = 1; rootc.ITEM_DESCRIPTION = answer.ANSWER_VALUE; rootc.LAST_UPD_BY = SessionManager.UserContext.UserName(); rootc.LAST_UPD_DT = DateTime.UtcNow; entities.AddToINCFORM_ROOT5Y(rootc); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 78).FirstOrDefault(); // causation if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { incident.INCFORM_LAST_STEP_COMPLETED = 125; // causation INCFORM_CAUSATION cause = new INCFORM_CAUSATION(); cause.INCIDENT_ID = incident.INCIDENT_ID; cause.CAUSEATION_CD = xlatList.Where(l => l.XLAT_GROUP == "INJURY_CAUSE" && l.DESCRIPTION == answer.ANSWER_VALUE).FirstOrDefault() == null ? "1000" : xlatList.Where(l => l.XLAT_GROUP == "INJURY_CAUSE" && l.DESCRIPTION == answer.ANSWER_VALUE).FirstOrDefault().XLAT_CODE; cause.LAST_UPD_BY = SessionManager.UserContext.UserName(); cause.LAST_UPD_DT = DateTime.UtcNow; entities.AddToINCFORM_CAUSATION(cause); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 27).FirstOrDefault(); // corrective action if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { incident.INCFORM_LAST_STEP_COMPLETED = 130; // corrective action TASK_STATUS action = new TASK_STATUS(); action.RECORD_TYPE = (int)TaskRecordType.HealthSafetyIncident; action.RECORD_ID = incident.INCIDENT_ID; action.TASK_STEP = ((int)SysPriv.action).ToString(); action.TASK_SEQ = 0; action.RECORD_SUBID = 0; action.TASK_TYPE = "T"; action.TASK_SEQ = 0; action.DESCRIPTION = answer.ANSWER_VALUE; action.DETAIL = incident.DESCRIPTION; action.STATUS = "1"; action.CREATE_ID = action.RESPONSIBLE_ID = action.COMPLETE_ID = incident.CREATE_PERSON; // default action values action.CREATE_DT = action.DUE_DT = action.COMPLETE_DT = incident.CREATE_DT; answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 79).FirstOrDefault(); // responsible if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { action.RESPONSIBLE_ID = action.COMPLETE_ID = decimal.Parse(answer.ANSWER_VALUE); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 65).FirstOrDefault(); // action due date if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { action.DUE_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 66).FirstOrDefault(); // action complete date if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { action.COMPLETE_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 70).FirstOrDefault(); // verification ? if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { action.COMMENTS = answer.ANSWER_VALUE; } entities.AddToTASK_STATUS(action); } if (incident.CLOSE_DATE_DATA_COMPLETE.HasValue || incident.CLOSE_DATE.HasValue) { incident.INCFORM_LAST_STEP_COMPLETED = 151; // signoff INCFORM_APPROVAL approval = new INCFORM_APPROVAL(); approval.INCIDENT_ID = incident.INCIDENT_ID; approval.ITEM_SEQ = (int)SysPriv.approve1; approval.APPROVAL_DATE = incident.CLOSE_DATE.HasValue ? incident.CLOSE_DATE : incident.CLOSE_DATE_DATA_COMPLETE; approval.IsAccepted = true; approval.APPROVER_PERSON_ID = incident.CLOSE_PERSON.HasValue ? incident.CLOSE_PERSON : incident.CREATE_PERSON; PERSON person = (from p in entities.PERSON where p.PERSON_ID == approval.APPROVER_PERSON_ID select p).FirstOrDefault(); approval.APPROVAL_MESSAGE = approval.APPROVER_PERSON = (person.FIRST_NAME + " " + person.LAST_NAME); answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 67).FirstOrDefault(); // completed by if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { approval.APPROVAL_MESSAGE = approval.APPROVER_PERSON = answer.ANSWER_VALUE; string[] names = answer.ANSWER_VALUE.ToLower().Split(' '); if (names.Length > 1) { string firstName = names[0]; string lastnamne = names[1]; person = (from p in entities.PERSON where p.FIRST_NAME.ToLower() == firstName && p.LAST_NAME.ToLower() == lastnamne select p).FirstOrDefault(); } } if (person != null) { approval.APPROVER_PERSON_ID = person.PERSON_ID; approval.APPROVER_TITLE = person.JOB_TITLE; } entities.AddToINCFORM_APPROVAL(approval); } if (issueType == EHSIncidentTypeId.InjuryIllness) { INCFORM_INJURYILLNESS inRec = new INCFORM_INJURYILLNESS(); INCFORM_WITNESS witness = new INCFORM_WITNESS(); INCFORM_LOSTTIME_HIST hist = new INCFORM_LOSTTIME_HIST(); inRec.INCIDENT_ID = incident.INCIDENT_ID; answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 6).FirstOrDefault(); // shift inRec.SHIFT = GetXLATCode(xlatList, "SHIFT", answer.ANSWER_VALUE); answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 7).FirstOrDefault(); // department if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.DEPARTMENT = answer.ANSWER_VALUE; DEPARTMENT dept = (from d in entities.DEPARTMENT where d.DEPT_NAME.ToLower() == answer.ANSWER_VALUE.ToLower() select d).SingleOrDefault(); if (dept != null) { inRec.DEPT_ID = dept.DEPT_ID; } } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 8).FirstOrDefault(); // involved person if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.INVOLVED_PERSON_NAME = answer.ANSWER_VALUE; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 4).FirstOrDefault(); // supervisor inform date if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.SUPERVISOR_INFORMED_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 5).FirstOrDefault(); // time of incident if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.INCIDENT_TIME = TimeSpan.Parse(answer.ANSWER_VALUE); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 9).FirstOrDefault(); // witness if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE) && answer.ANSWER_VALUE.Split(' ').Length > 1) { witness.INCIDENT_ID = incident.INCIDENT_ID; witness.WITNESS_NO = 1; witness.WITNESS_NAME = answer.ANSWER_VALUE; witness.LAST_UPD_BY = SessionManager.UserContext.UserName(); witness.LAST_UPD_DT = DateTime.UtcNow; entities.AddToINCFORM_WITNESS(witness); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 10).FirstOrDefault(); // inside/outside if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.INSIDE_OUTSIDE_BLDNG = GetXLATCode(xlatList, "IQ_10", answer.ANSWER_VALUE); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 11).FirstOrDefault(); // weather if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { ; // NO FIELD } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 12).FirstOrDefault(); // injury type if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.INJURY_TYPE = GetXLATCode(xlatList, "INJURY_TYPE", answer.ANSWER_VALUE); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 13).FirstOrDefault(); // body part if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.INJURY_BODY_PART = GetXLATCode(xlatList, "INJURY_PART", answer.ANSWER_VALUE); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 15).FirstOrDefault(); // reocurrance if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.REOCCUR = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 16).FirstOrDefault(); // first aid case if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.FIRST_AID = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 37).FirstOrDefault(); // employee if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.COMPANY_SUPERVISED = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 58).FirstOrDefault(); // specific description if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.DESCRIPTION_LOCAL = answer.ANSWER_VALUE; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 62).FirstOrDefault(); // recordable if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.RECORDABLE = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 63).FirstOrDefault(); // lost time case if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.LOST_TIME = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; if (inRec.LOST_TIME) { hist.INCIDENT_ID = incident.INCIDENT_ID; hist.WORK_STATUS = "03"; hist.ITEM_DESCRIPTION = "Lost Time"; hist.BEGIN_DT = incident.INCIDENT_DT; answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 3).FirstOrDefault(); // expected return date if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { hist.RETURN_EXPECTED_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null); } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 55).FirstOrDefault(); // actual return date if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { hist.RETURN_TOWORK_DT = DateTime.ParseExact(answer.ANSWER_VALUE, "M/d/yyyy hh:mm:ss tt", null); } hist.LAST_UPD_BY = SessionManager.UserContext.UserName(); hist.LAST_UPD_DT = DateTime.UtcNow; entities.AddToINCFORM_LOSTTIME_HIST(hist); } } answer = incident.INCIDENT_ANSWER.Where(a => a.INCIDENT_QUESTION_ID == 74).FirstOrDefault(); // occupational event ? if (answer != null && !string.IsNullOrEmpty(answer.ANSWER_VALUE)) { inRec.STD_PROCS_FOLLOWED = answer.ANSWER_VALUE.ToLower() == "yes" ? true : false; // map to std procedures ? } entities.AddToINCFORM_INJURYILLNESS(inRec); } status = entities.SaveChanges(); break; case EHSIncidentTypeId.PreventativeAction: break; default: break; } } catch { decimal id; id = incident.INCIDENT_ID; } } }