/// <summary> /// method /// US:902 /// runs the logic for all the checklists for the patient specified /// </summary> /// <param name="strPatientID"></param> /// <param name="lItemID"></param> /// <returns></returns> public CStatus RunLogic(string strPatientID) { CPatChecklistData pcl = new CPatChecklistData(this); DataSet dsPatientChecklists = null; CStatus status = pcl.GetPatChecklistDS(strPatientID, out dsPatientChecklists); if (!status.Status) { return(status); } CPatChecklistItemData pcli = new CPatChecklistItemData(this); foreach (DataRow drChecklist in dsPatientChecklists.Tables[0].Rows) { try { status = RunLogic(Convert.ToInt64(drChecklist["PAT_CL_ID"])); } catch { return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_RUN_LOGIC)); } if (!status.Status) { return(status); } } return(new CStatus()); }
/// <summary> /// US:912 /// Abstract save control method /// </summary> /// <returns></returns> public override CStatus SaveControl() { //update the checklist item states... CPatChecklistItemDataItem diCLItem = null; CPatChecklistItemData cid = new CPatChecklistItemData(BaseMstr.BaseData); CStatus status = cid.GetPatCLItemDI(PatientChecklistID, ItemID, out diCLItem); if (!status.Status) { return(status); } //per customer we only override decision state if (diCLItem.DSID != Convert.ToInt64(ddlDS.SelectedValue)) { diCLItem.IsOverridden = k_TRUE_FALSE_ID.True; diCLItem.OverrideDate = DateTime.Now; } diCLItem.DSID = CDropDownList.GetSelectedLongID(ddlDS); //update status = cid.UpdatePatChecklistItem(diCLItem); if (!status.Status) { return(status); } //keep a history of the ds override with comment if (diCLItem.IsOverridden == k_TRUE_FALSE_ID.True) { cid.OverridePatChecklistItem(diCLItem, txtComment.Text); } //TODO: this is obsolete, will delete after testing //we now keep a history of ds overrides with comment //using OverridePatChecklistItem above // //if (!string.IsNullOrEmpty(txtComment.Text)) //{ //CPatChecklistItemData item = new CPatChecklistItemData(BaseMstr.BaseData); //status = item.InsertPatientItemComment( // PatientChecklistID, // ChecklistID, // ItemID, // txtComment.Text); // if (!status.Status) // { // return status; // } // } return(new CStatus()); }
/// <summary> /// method /// US:909 /// disables the patient checklist item specified by the patient checklist it and item id /// </summary> /// <param name="lPatCLID"></param> /// <param name="lItemID"></param> /// <returns></returns> private CStatus DisableChecklistItem(long lPatCLID, long lItemID) { CPatChecklistItemData PatChecklistItem = new CPatChecklistItemData(BaseData); CPatChecklistItemDataItem di = null; CStatus status = PatChecklistItem.GetPatCLItemDI(lPatCLID, lItemID, out di); if (!status.Status) { return(status); } di.IsEnabled = k_TRUE_FALSE_ID.False; return(PatChecklistItem.UpdatePatChecklistItem(di)); }
/// <summary> /// US:912 /// load the comments history gridview /// </summary> public CStatus LoadCommentsGridView() { //itemdata for db work DataSet dsComments = null; CPatChecklistItemData item = new CPatChecklistItemData(BaseMstr.BaseData); CStatus status = item.GetPatItemOverrideCommmentDS(PatientChecklistID, ChecklistID, ItemID, out dsComments); if (!status.Status) { return(status); } gvComments.DataSource = dsComments; gvComments.DataBind(); return(new CStatus()); }
/// <summary> /// method /// US:902 /// returns the attribute specified by the place holder for the patient item specified by the patient checklist id and item id /// </summary> /// <param name="lPatCLID"></param> /// <param name="lItemID"></param> /// <param name="strPlaceHolder"></param> /// <returns></returns> private CStringStatus ParsePatCLI(long lPatCLID, long lItemID, string strPlaceHolder) { CPatChecklistItemData PatChecklistItem = new CPatChecklistItemData(BaseData); CPatChecklistItemDataItem di = null; CStatus status = PatChecklistItem.GetPatCLItemDI(lPatCLID, lItemID, out di); if (!status.Status) { return(new CStringStatus(status, CExpression.NullTkn)); } string strValue = CExpression.NullTkn; switch (strPlaceHolder) { case "temporalstate": strValue = (di.TSID < 1) ? CExpression.NullTkn : di.TSID.ToString(); break; case "temporalstate.state": strValue = (di.TSStateID < 1) ? CExpression.NullTkn : di.TSStateID.ToString(); break; case "outcomestate": strValue = (di.OSID < 1) ? CExpression.NullTkn : di.OSID.ToString(); break; case "outcomestate.state": strValue = (di.OSStateID < 1) ? CExpression.NullTkn : di.OSStateID.ToString(); break; case "decisionstate": strValue = (di.DSID < 1) ? CExpression.NullTkn : di.DSID.ToString(); break; case "decisionstate.state": strValue = (di.DSStateID < 1) ? CExpression.NullTkn : di.DSStateID.ToString(); break; } return(new CStringStatus(status, strValue)); }
/// <summary> /// US:912 /// select the current ts,os and ds states /// </summary> /// <returns></returns> public CStatus LoadStates() { CPatChecklistItemDataItem di = null; CPatChecklistItemData cid = new CPatChecklistItemData(BaseMstr.BaseData); CStatus status = cid.GetPatCLItemDI(PatientChecklistID, ItemID, out di); if (!status.Status) { return(status); } //temporal state CTemporalStateDataItem diTSi = new CTemporalStateDataItem(); CTemporalStateData tsdi = new CTemporalStateData(BaseMstr.BaseData); status = tsdi.GetTemporalStateDI(di.TSID, out diTSi); if (!status.Status) { return(status); } lblCurrentTS.Text = diTSi.TSLabel; //outcome state COutcomeStateDataItem diOSi = new COutcomeStateDataItem(); COutcomeStateData osdi = new COutcomeStateData(BaseMstr.BaseData); status = osdi.GetOutcomeStateDI(di.OSID, out diOSi); if (!status.Status) { return(status); } lblCurrentOS.Text = diOSi.OSLabel; //DS ddl select CDropDownList.SelectItemByValue(ddlDS, di.DSID); return(new CStatus()); }
/// <summary> /// method /// US:902 /// runs the logic for the specified patient checklist if it is open /// </summary> /// <param name="lPatCLID"></param> /// <returns></returns> public CStatus RunLogic(long lPatCLID) { CPatChecklistData pcl = new CPatChecklistData(this); CPatChecklistDataItem di = null; CStatus status = pcl.GetPatChecklistDI(lPatCLID, out di); if (!status.Status) { return(status); } if (di.ChecklistStateID != k_CHECKLIST_STATE_ID.Open) { return(new CStatus()); } DataSet dsChecklistItems = null; CPatChecklistItemData pcli = new CPatChecklistItemData(this); status = pcli.GetPatCLItemsByPatCLIDDS(lPatCLID, out dsChecklistItems); if (!status.Status) { return(status); } foreach (DataRow drItem in dsChecklistItems.Tables[0].Rows) { try { //get the item type id long lItemTypeID = Convert.ToInt64(drItem["ITEM_TYPE_ID"]); string strPatientID = drItem["PATIENT_ID"].ToString(); long lPatChecklistID = Convert.ToInt64(drItem["PAT_CL_ID"]); long lChecklistID = Convert.ToInt64(drItem["CHECKLIST_ID"]); long lItemID = Convert.ToInt64(drItem["ITEM_ID"]); CExpressionList expList = new CExpressionList( this, drItem["PATIENT_ID"].ToString(), Convert.ToInt64(drItem["PAT_CL_ID"]), Convert.ToInt64(drItem["CHECKLIST_ID"]), Convert.ToInt64(drItem["ITEM_ID"])); status = expList.Load(drItem["LOGIC"].ToString()); if (!status.Status) { return(status); } //run the default logic for the collection if (lItemTypeID == (long)k_ITEM_TYPE_ID.Collection) { CItemCollectionData ColData = new CItemCollectionData(this); status = ColData.RunCollectionLogic(strPatientID, lPatChecklistID, lChecklistID, lItemID); if (!status.Status) { return(status); } } //run custom logic for the item status = expList.Evaluate(); if (!status.Status) { return(status); } } catch (Exception) { return(new CStatus( false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_RUN_LOGIC)); } } return(new CStatus()); }
/// <summary> /// Generates the TIU text for a patient checklist /// </summary> /// <param name="strPatientID"></param> /// <param name="lPatCLID"></param> /// <param name="strText"></param> /// <returns></returns> public CStatus GetTIUText(string strPatientID, long lPatCLID, out string strNoteTitleTag, out string strText) { strText = string.Empty; strNoteTitleTag = string.Empty; CStatus status = new CStatus(); //patient data - get the di just in case we need more than the blurb CPatientDataItem diPat = new CPatientDataItem(); CPatientData patData = new CPatientData(this); status = patData.GetPatientDI(strPatientID, out diPat); //get the patient blurb string strBlurb = String.Empty; patData.GetPatientBlurb(strPatientID, out strBlurb); //build the TIU note text... //legend strText += "Definitions:\r\n"; //ts strText += CDataUtils.DelimitString("TS = The temporal state of an attribute defines whether the patient has had the test or event within a given time period", "\r\n", 80); strText += "\r\n"; //os strText += CDataUtils.DelimitString("OS = The outcome state of an attribute defines the resultant state of an attribute (e.g. normal, abnormal, problem/decision required)", "\r\n", 80); strText += "\r\n"; //ds strText += CDataUtils.DelimitString("DS = The decision state of an attribute defines a rule-based state of an attribute (e.g. Go, No-Go)", "\r\n", 80); strText += "\r\n"; strText += "\r\n"; DateTime dtNoteDate = DateTime.Now; string strNoteDate = CDataUtils.GetDateTimeAsString(dtNoteDate); strText += "Date: " + strNoteDate; strText += "\r\n\r\n"; //--demographics strText += CDataUtils.DelimitString(strBlurb, "\r\n", 80); strText += "\r\n"; //patient checklist data CPatChecklistDataItem diPatChecklist = new CPatChecklistDataItem(); status = GetPatChecklistDI(lPatCLID, out diPatChecklist); //checklist data CChecklistDataItem diChecklist = new CChecklistDataItem(); CChecklistData clData = new CChecklistData(this); status = clData.GetCheckListDI(diPatChecklist.ChecklistID, out diChecklist); //get the note title tag for the checklist, this is used to //write the correct note to MDWS strNoteTitleTag = diChecklist.NoteTitleTag; //--Checklist Name strText += "Checklist: "; strText += CDataUtils.DelimitString(diChecklist.ChecklistLabel, "\r\n", 80); strText += "\r\n"; //--Procedure Date strText += "Procedure Date: "; if (!CDataUtils.IsDateNull(diPatChecklist.ProcedureDate)) { strText += CDataUtils.GetDateAsString(diPatChecklist.ProcedureDate); } else { strText += "None"; } strText += "\r\n\r\n"; //patient checklist items and overall state long lColTSStateID = 0; long lColOSStateID = 0; long lColDSStateID = 0; long lSummaryStateID = 0; DataSet dsItems = null; CPatChecklistItemData diCLI = new CPatChecklistItemData(this); status = diCLI.GetPatCLItemsByPatCLIDDS(lPatCLID, out lColTSStateID, out lColOSStateID, out lColDSStateID, out lSummaryStateID, out dsItems); //--overall Checklist state string strOverallState = "Unknown"; switch (lSummaryStateID) { case (long)k_STATE_ID.Bad: strOverallState = "Bad"; break; case (long)k_STATE_ID.Good: strOverallState = "Good"; break; } strText += "Overall Checklist State: "; strText += strOverallState; strText += "\r\n\r\n"; strText += "Checklist Items:"; strText += "\r\n\r\n"; //loop over checklist items foreach (DataTable table in dsItems.Tables) { foreach (DataRow dr in table.Rows) { CPatChecklistItemDataItem itm = new CPatChecklistItemDataItem(dr); if (itm != null) { //get the data for the item CItemDataItem idi = new CItemDataItem(); CItemData itmData = new CItemData(this); itmData.GetItemDI(itm.ItemID, out idi); strText += CDataUtils.DelimitString("* " + idi.ItemLabel, "\r\n", 80); strText += "\r\n"; //temporal state CTemporalStateDataItem diTSi = new CTemporalStateDataItem(); CTemporalStateData tsdi = new CTemporalStateData(this); tsdi.GetTemporalStateDI(itm.TSID, out diTSi); strText += "TS: "; strText += CDataUtils.DelimitString(diTSi.TSLabel, "\r\n", 80); strText += " "; //outcome state COutcomeStateDataItem diOSi = new COutcomeStateDataItem(); COutcomeStateData osdi = new COutcomeStateData(this); osdi.GetOutcomeStateDI(itm.OSID, out diOSi); strText += "OS: "; strText += CDataUtils.DelimitString(diOSi.OSLabel, "\r\n", 80); strText += " "; //decision state CDecisionStateDataItem diDSi = new CDecisionStateDataItem(); CDecisionStateData dsdi = new CDecisionStateData(this); dsdi.GetDecisionStateDI(itm.DSID, out diDSi); string strDS = String.Empty; strDS += "DS: "; strDS += diDSi.DSLabel; //if decision state is overriden pull out the //last comment if (itm.IsOverridden == k_TRUE_FALSE_ID.True) { DataSet dsComments = null; //todo: override history is now stored in a diff table //this is obsolete will delete after testing //status = diCLI.GetPatientItemCommmentDS( // itm.PatCLID, // itm.ItemID, // out dsComments); status = diCLI.GetPatItemOverrideCommmentDS(itm.PatCLID, itm.ChecklistID, itm.ItemID, out dsComments); //first record is the newest comment if (!CDataUtils.IsEmpty(dsComments)) { //string strComment = CDataUtils.GetDSStringValue(dsComments, "comment_text"); //DateTime dtComment = CDataUtils.GetDSDateTimeValue(dsComments, "comment_date"); // string strComment = CDataUtils.GetDSStringValue(dsComments, "override_comment"); DateTime dtComment = CDataUtils.GetDSDateTimeValue(dsComments, "override_date"); long lCommentUserID = CDataUtils.GetDSLongValue(dsComments, "user_id"); DataSet dsUser = null; CUserData ud = new CUserData(this); ud.GetUserDS(lCommentUserID, out dsUser); string strUser = String.Empty; if (!CDataUtils.IsEmpty(dsUser)) { strUser = CDataUtils.GetDSStringValue(dsUser, "name"); } strDS += " Overridden "; strDS += CDataUtils.GetDateAsString(dtComment); strDS += " "; strDS += strUser; strDS += "\r\n\r\n"; strDS += strComment; } } //ds strText += CDataUtils.DelimitString(strDS, "\r\n", 80); strText += "\r\n\r\n"; } } } return(status); }
/// <summary> /// method /// US:902 /// evaluates all the expressions in the list /// </summary> /// <returns></returns> public CStatus Evaluate() { CParseExpression ParseExp = new CParseExpression(BaseData, PatientID, PatCLID, ChecklistID, ItemID); CStatus status = new CStatus(); foreach (CExpression exp in this) { CStringStatus ss = ParseExp.Parse(exp.GetIf()); if (!ss.Status) { status = ss; break; } if (ss.Value.IndexOf(CExpression.NullTkn) >= 0) { CPatChecklistItemData PatChecklistItem = new CPatChecklistItemData(BaseData); CPatChecklistItemDataItem di = null; status = PatChecklistItem.GetPatCLItemDI(PatCLID, ItemID, out di); if (!status.Status) { return(status); } di.TSID = Convert.ToInt64(k_DEFAULT_STATE_ID.Bad); di.OSID = Convert.ToInt64(k_DEFAULT_STATE_ID.Unknown); di.IsOverridden = k_TRUE_FALSE_ID.False; di.OverrideDate = CDataUtils.GetNullDate(); di.DSID = Convert.ToInt64(k_DEFAULT_STATE_ID.Bad); status = PatChecklistItem.UpdatePatChecklistItem(di); if (!status.Status) { return(status); } continue; } int nResult = CLogic.Evaluate(ss.Value); CExecuteExpression ExecuteExp = new CExecuteExpression( BaseData, PatientID, PatCLID, ChecklistID, ItemID); switch (nResult) { // false case 0: string strElse = exp.GetElse(); if (!string.IsNullOrEmpty(strElse)) { status = ExecuteExp.Execute(strElse); } break; // true case 1: status = ExecuteExp.Execute(exp.GetThen()); break; // error case 2: status.Status = false; status.StatusCode = k_STATUS_CODE.Failed; status.StatusComment = LogicModuleMessages.ERROR_LOGIC + exp.Expression; break; } if (!status.Status) { break; } } return(status); }
/// <summary> /// override /// US:880 /// loads the user control with the data related to the patient checklist id stored in the patient checklist id property /// </summary> /// <param name="lEditMode"></param> /// <returns></returns> public override CStatus LoadControl(k_EDIT_MODE lEditMode) { EditMode = lEditMode; CPatChecklistItemData pci = new CPatChecklistItemData(BaseMstr.BaseData); long lTSColStateID = 0; long lOSColStateID = 0; long lDSColStateID = 0; long lSummaryStateID = 0; DataSet dsChecklistItems = null; CStatus statusPatCL = pci.GetPatCLItemsByPatCLIDDS( PatientChecklistID, out lTSColStateID, out lOSColStateID, out lDSColStateID, out lSummaryStateID, out dsChecklistItems); if (!statusPatCL.Status) { return(statusPatCL); } TSColStateID = lTSColStateID; OSColStateID = lOSColStateID; DSColStateID = lDSColStateID; lblSummaryState.Visible = true; imgSummaryState.Visible = true; switch (lSummaryStateID) { case (long)k_STATE_ID.Bad: imgSummaryState.ImageUrl = Resources.Images.STATE_BAD_LARGE; break; case (long)k_STATE_ID.Good: imgSummaryState.ImageUrl = Resources.Images.STATE_GOOD_LARGE; break; default: imgSummaryState.ImageUrl = Resources.Images.STATE_UNKNOWN_LARGE; break; } CPatientData p = new CPatientData(BaseMstr.BaseData); DataSet dsPatientItems = null; CStatus statusPatItems = p.GetPatItemsByPatCLIDDS(PatientChecklistID, out dsPatientItems); if (!statusPatItems.Status) { return(statusPatItems); } PatientItems = dsPatientItems.Tables[0]; DataSet dsPatientItemComponents = null; CStatus statusPatItemComps = p.GetPatItemCompsByPatCLIDDS(PatientChecklistID, out dsPatientItemComponents); if (!statusPatItemComps.Status) { return(statusPatItemComps); } PatientItemComponents = dsPatientItemComponents.Tables[0]; gvPatCLItems.DataSource = dsChecklistItems.Tables[0]; gvPatCLItems.DataBind(); //set the ui permissions based on the users role SetPermissions(); return(new CStatus()); }
/// <summary> /// method /// US:910 /// executes the action specified by the action string on the patient checklist item specified by the patient checklist id and item id /// </summary> /// <param name="lPatCLID"></param> /// <param name="lItemID"></param> /// <param name="strProperty"></param> /// <param name="strAction"></param> /// <param name="lID"></param> /// <returns></returns> private CStatus ExecutePatCLI( long lPatCLID, long lItemID, string strProperty, string strAction, long lID) { CPatChecklistItemData PatChecklistItem = new CPatChecklistItemData(BaseData); CPatChecklistItemDataItem di = null; CStatus status = PatChecklistItem.GetPatCLItemDI(lPatCLID, lItemID, out di); if (!status.Status) { return(status); } switch (strAction) { case "set": switch (strProperty) { case "temporalstate": di.TSID = lID; break; case "outcomestate": di.OSID = lID; break; case "decisionstate": if (di.IsOverridden == k_TRUE_FALSE_ID.True) { CPatientItemData pi = new CPatientItemData(BaseData); CPatientItemDataItem pidi = null; status = pi.GetMostRecentPatientItemDI( PatientID, lItemID, out pidi); if (!status.Status) { return(status); } if (di.OverrideDate < pidi.EntryDate) { di.IsOverridden = k_TRUE_FALSE_ID.False; di.OverrideDate = CDataUtils.GetNullDate(); di.DSID = lID; } } else { di.DSID = lID; } break; } return(PatChecklistItem.UpdatePatChecklistItem(di)); default: return(new CStatus(false, k_STATUS_CODE.Failed, LogicModuleMessages.ERROR_EXE_EXP + strProperty + CExpression.SpecifierTkn + strAction + CExpression.ParamStartTkn + lID.ToString() + CExpression.ParamEndTkn)); } }
/// <summary> /// method to run logic over a colletion /// 1. all items in multi select must be have an option selected /// 2. all free text items must have data entered /// 3. labs and note titles are ignored /// 4. items that are not ACTIVE are ignored /// </summary> public CStatus RunCollectionLogic(string strPatientID, long lPatChecklistID, long lChecklistID, long lCollectionItemID) { //Get the patient checklist item data CPatChecklistItemData PatChecklistItem = new CPatChecklistItemData(this); CPatChecklistItemDataItem pdi = null; PatChecklistItem.GetPatCLItemDI(lPatChecklistID, lCollectionItemID, out pdi); //get all the items in the collection CItemCollectionData coll = new CItemCollectionData(this); DataSet dsColl = null; CStatus status = coll.GetItemCollectionDS(lCollectionItemID, out dsColl); //get all the patient item components in the collection DataSet dsPatItemComps = null; status = coll.GetItemColMostRecentPatICDS(lCollectionItemID, strPatientID, out dsPatItemComps); //if this collection item is overridden just return and don't update the state if (pdi.IsOverridden == k_TRUE_FALSE_ID.True) { bool bReturn = true; //check to see if there is a new result and override if there is... foreach (DataTable tableI in dsColl.Tables) { foreach (DataRow drI in tableI.Rows) { //get values from the the item in the collection (not the patient items, the collection items) long lItemID = CDataUtils.GetDSLongValue(drI, "ITEM_ID"); long lItemTypeID = CDataUtils.GetDSLongValue(drI, "ITEM_TYPE_ID"); long lActiveID = CDataUtils.GetDSLongValue(drI, "ACTIVE_ID"); //get the item so we can check entry date against TS etc... CPatientItemDataItem patItemDI = null; CPatientItemData patData = new CPatientItemData(this); patData.GetMostRecentPatientItemDI(strPatientID, lItemID, out patItemDI); DateTime dtEntryDate = patItemDI.EntryDate; if (dtEntryDate > pdi.OverrideDate) { pdi.OverrideDate = CDataUtils.GetNullDate(); pdi.IsOverridden = k_TRUE_FALSE_ID.False; PatChecklistItem.UpdatePatChecklistItem(pdi); bReturn = false; break; } } } if (bReturn) { //return if this item is overridden and there are no new results return(new CStatus()); } } //get the checklist item di CChecklistItemDataItem cidDI = null; CChecklistItemData cid = new CChecklistItemData(this); cid.GetCLItemDI(lChecklistID, lCollectionItemID, out cidDI); //calculate how far the TS can go back long lTS = cidDI.CLITSTimePeriod; DateTime dtNow = DateTime.Now; DateTime dtTSCompare = dtNow.AddDays(-1 * lTS); //keeps the overall OS state of the items k_STATE_ID kOverallOSStateID = k_STATE_ID.NotSelected; //keeps the overall TS state of the items k_STATE_ID kOverallTSStateID = k_STATE_ID.NotSelected; //loop over the collection items foreach (DataTable table in dsColl.Tables) { foreach (DataRow dr in table.Rows) { //get values from the the item in the collection (not the patient items, the collection items) long lItemID = CDataUtils.GetDSLongValue(dr, "ITEM_ID"); long lItemTypeID = CDataUtils.GetDSLongValue(dr, "ITEM_TYPE_ID"); long lActiveID = CDataUtils.GetDSLongValue(dr, "ACTIVE_ID"); //get the item so we can check entry date against TS etc... CPatientItemDataItem patItemDI = null; CPatientItemData patData = new CPatientItemData(this); patData.GetMostRecentPatientItemDI(strPatientID, lItemID, out patItemDI); DateTime dtEntryDate = patItemDI.EntryDate; //only interested in ACTIVE items if ((k_ACTIVE)lActiveID == k_ACTIVE.ACTIVE) { //check the TS and set overall TS state k_COMPARE kTS = CDataUtils.CompareDates(dtEntryDate, dtTSCompare); if (kTS == k_COMPARE.GREATERTHAN || kTS == k_COMPARE.EQUALTO) { //good if (kOverallTSStateID != k_STATE_ID.Bad) { kOverallTSStateID = k_STATE_ID.Good; } } else { //bad kOverallTSStateID = k_STATE_ID.Bad; } //list to hold the created component items CPatientItemCompList PatItemCompList = new CPatientItemCompList(); //build a pat item component list loaded with the most recent //values foreach (DataTable tableComp in dsPatItemComps.Tables) { foreach (DataRow drComp in tableComp.Rows) { //values to load the component item long lCompItemID = CDataUtils.GetDSLongValue(drComp, "ITEM_ID"); long lComponentID = CDataUtils.GetDSLongValue(drComp, "ITEM_COMPONENT_ID"); string strComponentValue = CDataUtils.GetDSStringValue(drComp, "COMPONENT_VALUE"); long lPatItemID = CDataUtils.GetDSLongValue(drComp, "PAT_ITEM_ID"); //only this item if (lCompItemID == lItemID) { CPatientItemComponentDataItem diComp = new CPatientItemComponentDataItem(); diComp.PatientID = strPatientID; diComp.ItemID = lCompItemID; diComp.ComponentID = lComponentID; diComp.ComponentValue = strComponentValue; diComp.PatItemID = lPatItemID; PatItemCompList.Add(diComp); } } //we now have a list of item components for this item //loop and get status for this item and update the overall status bool bHasSelectedValue = false; foreach (CPatientItemComponentDataItem diPatItemComp in PatItemCompList) { //get the state id for this component CICStateDataItem sdi = null; CItemComponentData icd = new CItemComponentData(this); icd.GetICStateDI(lItemID, diPatItemComp.ComponentID, out sdi); //switch on the type and get the value switch ((k_ITEM_TYPE_ID)lItemTypeID) { case k_ITEM_TYPE_ID.Laboratory: { bHasSelectedValue = true; //get the ranges CICRangeDataItem rdi = null; icd.GetICRangeDI(lItemID, diPatItemComp.ComponentID, out rdi); if (String.IsNullOrEmpty(diPatItemComp.ComponentValue)) { //does not have a value? kOverallOSStateID = k_STATE_ID.Unknown; } else { try { double dblValue = Convert.ToDouble(diPatItemComp.ComponentValue); //max/high check if (dblValue >= rdi.LegalMax) { if (kOverallOSStateID != k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Unknown; } } else { if (dblValue >= rdi.High) { kOverallOSStateID = k_STATE_ID.Bad; } else { if (kOverallOSStateID != k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Good; } } } //min/low check if (dblValue <= rdi.LegalMin) { if (kOverallOSStateID != k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Unknown; } } else { if (dblValue <= rdi.Low) { kOverallOSStateID = k_STATE_ID.Bad; } else { if (kOverallOSStateID != k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Good; } } } } catch (Exception e) { if (kOverallOSStateID != k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Unknown; } } } break; } case k_ITEM_TYPE_ID.NoteTitle: { //note titles are excluded from quick entry //so if we have one our os state is unknown bHasSelectedValue = true; kOverallOSStateID = k_STATE_ID.Unknown; break; } case k_ITEM_TYPE_ID.QuestionFreeText: { bHasSelectedValue = true; if (diPatItemComp.ComponentValue.Length < 1) { //if they did not enter a value //then the overall state is bad! kOverallOSStateID = k_STATE_ID.Bad; } break; } case k_ITEM_TYPE_ID.QuestionSelection: if (!String.IsNullOrEmpty(diPatItemComp.ComponentValue)) { //only interested in the one they selected if ((k_TRUE_FALSE_ID)Convert.ToInt64(diPatItemComp.ComponentValue) != k_TRUE_FALSE_ID.False) { bHasSelectedValue = true; if (kOverallOSStateID != k_STATE_ID.Bad) { if ((k_STATE_ID)sdi.StateID == k_STATE_ID.Bad) { kOverallOSStateID = k_STATE_ID.Bad; } else { if ((k_STATE_ID)sdi.StateID == k_STATE_ID.Good) { if (kOverallOSStateID != k_STATE_ID.Unknown) { kOverallOSStateID = k_STATE_ID.Good; } } else { kOverallOSStateID = k_STATE_ID.Unknown; } } } } } break; } }//for each //if there is nothing selected then the //overall TS state is bad and the OS state is unknown if (!bHasSelectedValue) { kOverallOSStateID = k_STATE_ID.Unknown; kOverallTSStateID = k_STATE_ID.Bad; } } } } } // //now update the collection item states. // //get the ts,os and ds possible values CChecklistItemData dCL = new CChecklistItemData(this); DataSet dsTS = null; dCL.GetTemporalStateDS(lChecklistID, lCollectionItemID, out dsTS); long lGoodTSID = dCL.GetTSDefaultStateID(dsTS, k_STATE_ID.Good); long lBadTSID = dCL.GetTSDefaultStateID(dsTS, k_STATE_ID.Bad); long lUnknownTSID = dCL.GetTSDefaultStateID(dsTS, k_STATE_ID.Unknown); DataSet dsOS = null; dCL.GetOutcomeStateDS(lChecklistID, lCollectionItemID, out dsOS); long lGoodOSID = dCL.GetOSDefaultStateID(dsOS, k_STATE_ID.Good); long lBadOSID = dCL.GetOSDefaultStateID(dsOS, k_STATE_ID.Bad); long lUnknownOSID = dCL.GetOSDefaultStateID(dsOS, k_STATE_ID.Unknown); DataSet dsDS = null; dCL.GetDecisionStateDS(lChecklistID, lCollectionItemID, out dsDS); long lGoodDSID = dCL.GetDSDefaultStateID(dsDS, k_STATE_ID.Good); long lBadDSID = dCL.GetDSDefaultStateID(dsDS, k_STATE_ID.Bad); long lUnknownDSID = dCL.GetDSDefaultStateID(dsDS, k_STATE_ID.Unknown); //update the TS state on the data item if (kOverallTSStateID == k_STATE_ID.Bad) { pdi.TSID = lBadTSID; } else if (kOverallTSStateID == k_STATE_ID.Good) { pdi.TSID = lGoodTSID; } else { pdi.TSID = lUnknownTSID; } //update the OS state on the data item if (kOverallOSStateID == k_STATE_ID.Bad) { pdi.OSID = lBadOSID; } else if (kOverallOSStateID == k_STATE_ID.Good) { pdi.OSID = lGoodOSID; } else { pdi.OSID = lUnknownOSID; } //update the ds state on the item data if (kOverallTSStateID == k_STATE_ID.Good && kOverallOSStateID == k_STATE_ID.Good) { pdi.DSID = lGoodDSID; } else { pdi.DSID = lBadDSID; } //update the checklist item state status = PatChecklistItem.UpdatePatChecklistItem(pdi); return(status); }