Exemplo n.º 1
0
    public override CStatus SaveControl()
    {
        //get the checked temporal states
        string strTSIDs = CGridView.GetCheckedRows(
            gvTS,
            "chkSelect");

        long lTSCount = strTSIDs.Split(',').Count();

        //save the temporal states
        CChecklistItemData itm    = new CChecklistItemData(BaseMstr.BaseData);
        CStatus            status = itm.SaveTemporalStates(
            ChecklistID,
            ChecklistItemID,
            strTSIDs,
            lTSCount);

        if (!status.Status)
        {
            ShowStatusInfo(status);
            ShowMPE();
            return(status);
        }

        return(new CStatus());
    }
Exemplo n.º 2
0
    /// <summary>
    /// US:912
    /// loads a dropdown list of decision states
    /// </summary>
    /// <returns></returns>
    public static CStatus LoadCLIDecisionStatesDDL(
        CData Data,
        long lChecklistID,
        long lItemID,
        DropDownList ddl)
    {
        ddl.Items.Clear();

        DataSet            dsDS   = null;
        CChecklistItemData cid    = new CChecklistItemData(Data);
        CStatus            status = cid.GetDecisionStateDS(lChecklistID, lItemID, out dsDS);

        if (!status.Status)
        {
            return(status);
        }

        //render the dataset
        status = CDropDownList.RenderDataSet(
            dsDS,
            ddl,
            "DS_LABEL",
            "DS_ID");
        if (!status.Status)
        {
            return(status);
        }

        return(new CStatus());
    }
Exemplo n.º 3
0
    /// <summary>
    /// method
    /// US:902
    /// returns the attribute specified by the specifier for the checklist item specified by the checklist id and item id
    /// </summary>
    /// <param name="lChecklistID"></param>
    /// <param name="lItemID"></param>
    /// <param name="strSpecifier"></param>
    /// <returns></returns>
    private CStringStatus ParseCLI(long lChecklistID, long lItemID, string strSpecifier)
    {
        CChecklistItemData     ChecklistItem = new CChecklistItemData(BaseData);
        CChecklistItemDataItem di            = null;
        CStatus status = ChecklistItem.GetCLItemDI(ChecklistID, lItemID, out di);

        if (!status.Status)
        {
            return(new CStringStatus(status, CExpression.NullTkn));
        }

        string strValue = CExpression.NullTkn;

        switch (strSpecifier)
        {
        case "tstimeperiod":
            strValue = (di.CLITSTimePeriod < 1) ? CExpression.NullTkn : di.CLITSTimePeriod.ToString();
            break;

        case "tstimeperioddate":
            return(CalcTSTimePeriodDate(di));
        }

        return(new CStringStatus(status, strValue));
    }
    /// <summary>
    /// method
    /// saves the roles that may edit the decision state for an item to the database
    /// </summary>
    /// <param name="lItemID"></param>
    /// <returns></returns>
    protected CStatus SaveCLIDSEdit(long lItemID)
    {
        CChecklistItemData clid   = new CChecklistItemData(BaseMstr.BaseData);
        CStatus            status = clid.DeleteAllCLItemDSRoles(ChecklistID, lItemID);

        if (!status.Status)
        {
            return(status);
        }

        string strDSSelect = "ITEM_ID = " + lItemID.ToString();

        DataRow[] adr = DSChangeable.Select(strDSSelect);
        foreach (DataRow dr in adr)
        {
            CCLIDSEditDataItem di = new CCLIDSEditDataItem();
            di.ChecklistID = ChecklistID;
            di.ItemID      = lItemID;
            di.UserRoleID  = Convert.ToInt64(dr["USER_ROLE_ID"]);

            status = clid.InsertCLItemDSRole(di);
            if (!status.Status)
            {
                return(status);
            }
        }

        return(new CStatus());
    }
Exemplo n.º 5
0
    /// <summary>
    /// method
    /// saves a checklist item to the database
    /// </summary>
    /// <param name="dr"></param>
    /// <returns></returns>
    protected CStatus SaveChecklistItem(DataRow dr)
    {
        CChecklistItemDataItem clidi = new CChecklistItemDataItem();
        clidi.ChecklistID = Convert.ToInt64(dr["CHECKLIST_ID"]);
        clidi.ItemID = Convert.ToInt64(dr["ITEM_ID"]);
        clidi.CLITSTimePeriod = Convert.ToInt64(dr["CLI_TS_TIME_PERIOD"]);
        clidi.TimeUnitID = (k_TIME_UNIT_ID)Convert.ToInt64(dr["TIME_UNIT_ID"]);
        clidi.SortOrder = Convert.ToInt64(dr["SORT_ORDER"]);
        clidi.ActiveID = (k_ACTIVE_ID)Convert.ToInt64(dr["ACTIVE_ID"]);

        CChecklistItemData clid = new CChecklistItemData(BaseMstr.BaseData);
        if (clidi.ChecklistID < 1)
        {
            //get the item type id
            long lItemTypeID = -1;
            
            CItemDataItem idi = null;
            CItemData id = new CItemData(BaseMstr.BaseData);
            id.GetItemDI(clidi.ItemID, out idi);
            lItemTypeID = idi.ItemTypeID;
            
            clidi.ChecklistID = ChecklistID;
            
            //do not generate default logic for a collection item.
            //default logic for a collection is handled in a seperate call.
            if((k_ITEM_TYPE_ID)lItemTypeID == k_ITEM_TYPE_ID.Collection)
            {
                clidi.Logic = "";
            }
            else
            {
                clidi.Logic = CExpression.DefaultTemporalLogic
                + " " + CExpression.DefaultOutcomeLogic
                + " " + CExpression.DefaultDecisionLogic;
            }

            CStatus status = clid.InsertChecklistItem(clidi);
            if (!status.Status)
            {
                return status;
            }

            dr["CHECKLIST_ID"] = ChecklistID;
        }
        else
        {
            CStatus status = clid.UpdateChecklistItem(clidi);
            if (!status.Status)
            {
                return status;
            }
        }

        return new CStatus();
    }
    /// <summary>
    /// method
    /// US:902
    /// loads all the logic expressions for an item into the list
    /// </summary>
    /// <param name="lChecklistID"></param>
    /// <param name="lItemID"></param>
    /// <returns></returns>
    public CStatus Load()
    {
        string                 strItemLogic = string.Empty;
        CChecklistItemData     dta          = new CChecklistItemData(BaseData);
        CChecklistItemDataItem di           = null;
        CStatus                status       = dta.GetCLItemDI(ChecklistID, ItemID, out di);

        if (!status.Status)
        {
            return(status);
        }

        SplitAddLogicExpressions(di.Logic);
        return(new CStatus());
    }
Exemplo n.º 7
0
    public override CStatus LoadControl(k_EDIT_MODE lEditMode)
    {
        EditMode = lEditMode;

        //get the data
        DataSet            ds     = null;
        CTemporalStateData tsd    = new CTemporalStateData(BaseMstr.BaseData);
        CStatus            status = tsd.GetTemporalStateDS((long)k_ACTIVE_ID.Active, out ds);

        if (!status.Status)
        {
            return(status);
        }

        TemporalStates  = ds.Tables[0];
        gvTS.DataSource = TemporalStates;
        gvTS.DataBind();

        //get the cli data and check the checkboxes
        CChecklistItemData itemData = new CChecklistItemData(BaseMstr.BaseData);
        DataSet            dsTS     = null;

        status = itemData.GetTemporalStateDS(ChecklistID, ChecklistItemID, out dsTS);
        if (!status.Status)
        {
            return(status);
        }

        string strTSIDs = ",";

        foreach (DataRow dr in dsTS.Tables[0].Rows)
        {
            strTSIDs += dr["ts_id"].ToString() + ",";
        }

        TemporalStateIDs = strTSIDs;
        CGridView.SetCheckedRows(
            gvTS,
            TemporalStateIDs,
            "chkSelect");

        return(new CStatus());
    }
    /// <summary>
    /// override
    /// loads the data sets required to load the item list
    /// </summary>
    /// <param name="lEditMode"></param>
    /// <returns></returns>
    public override CStatus LoadControl(k_EDIT_MODE lEditMode)
    {
        EditMode = lEditMode;

        if (EditMode == k_EDIT_MODE.UPDATE)
        {
            CChecklistData cld            = new CChecklistData(BaseMstr.BaseData);
            DataSet        dsDSChangeable = null;
            CStatus        status         = cld.GetChecklistDSChangeableDS(ChecklistID, out dsDSChangeable);
            if (!status.Status)
            {
                ShowStatusInfo(status);
                return(status);
            }

            DSChangeable = dsDSChangeable.Tables[0];

            CChecklistItemData clid            = new CChecklistItemData(BaseMstr.BaseData);
            DataSet            dsChecklistItem = null;
            status = clid.GetChecklistItemsDS(ChecklistID, out dsChecklistItem);
            if (!status.Status)
            {
                ShowStatusInfo(status);
                return(status);
            }

            Items = dsChecklistItem.Tables[0];
            gvChecklistItems.DataSource = Items;
            gvChecklistItems.DataBind();
        }
        else
        {
            ChecklistID = 0;
            gvChecklistItems.DataSource = null;
            gvChecklistItems.DataBind();
            InitializeDataTables();
        }

        return(new CStatus());
    }
    /// <summary>
    /// method
    /// saves a checklist item to the database
    /// </summary>
    /// <param name="dr"></param>
    /// <returns></returns>
    protected CStatus SaveChecklistItem(DataRow dr)
    {
        CChecklistItemDataItem clidi = new CChecklistItemDataItem();

        clidi.ChecklistID     = Convert.ToInt64(dr["CHECKLIST_ID"]);
        clidi.ItemID          = Convert.ToInt64(dr["ITEM_ID"]);
        clidi.CLITSTimePeriod = Convert.ToInt64(dr["CLI_TS_TIME_PERIOD"]);
        clidi.TimeUnitID      = (k_TIME_UNIT_ID)Convert.ToInt64(dr["TIME_UNIT_ID"]);
        clidi.SortOrder       = Convert.ToInt64(dr["SORT_ORDER"]);
        clidi.ActiveID        = (k_ACTIVE_ID)Convert.ToInt64(dr["ACTIVE_ID"]);

        CChecklistItemData clid = new CChecklistItemData(BaseMstr.BaseData);

        if (clidi.ChecklistID < 1)
        {
            clidi.ChecklistID = ChecklistID;
            clidi.Logic       = CExpression.DefaultTemporalLogic
                                + " " + CExpression.DefaultOutcomeLogic
                                + " " + CExpression.DefaultDecisionLogic;

            CStatus status = clid.InsertChecklistItem(clidi);
            if (!status.Status)
            {
                return(status);
            }

            dr["CHECKLIST_ID"] = ChecklistID;
        }
        else
        {
            CStatus status = clid.UpdateChecklistItem(clidi);
            if (!status.Status)
            {
                return(status);
            }
        }

        return(new CStatus());
    }
Exemplo n.º 10
0
    /// <summary>
    /// US:1384
    /// override
    /// calls the grid view loads
    /// </summary>
    /// <param name="lEditMode"></param>
    /// <param name="lStatusCode"></param>
    /// <param name="strStatusComment"></param>
    /// <returns></returns>
    public override CStatus LoadControl(k_EDIT_MODE lEditMode)
    {
        Title = "State/Logic Editor";
        btnucSave.Focus();

        CItemData     item   = new CItemData(BaseMstr.BaseData);
        CItemDataItem di     = null;
        CStatus       status = item.GetItemDI(ChecklistItemID, out di);

        if (!status.Status)
        {
            return(status);
        }

        hItem.InnerText = di.ItemLabel;

        //load the gridviews with static data
        ucStateLogicSelector.ChecklistID     = ChecklistID;
        ucStateLogicSelector.ChecklistItemID = ChecklistItemID;
        status = ucStateLogicSelector.LoadControl(lEditMode);
        if (!status.Status)
        {
            return(status);
        }

        CChecklistItemData     dta     = new CChecklistItemData(BaseMstr.BaseData);
        CChecklistItemDataItem diLogic = null;

        status = dta.GetCLItemDI(ChecklistID, ChecklistItemID, out diLogic);
        if (!status.Status)
        {
            return(status);
        }

        txtItemLogic.Text = diLogic.Logic;

        return(new CStatus());
    }
Exemplo n.º 11
0
    /// <summary>
    /// US:1384
    /// override
    /// saves the user's selection for each grid view in the database
    /// </summary>
    /// <param name="lStatusCode"></param>
    /// <param name="strStatusComment"></param>
    /// <returns></returns>
    public override CStatus SaveControl()
    {
        //save
        CStatus status = ucStateLogicSelector.SaveControl();

        if (!status.Status)
        {
            return(status);
        }

        CChecklistItemData data = new CChecklistItemData(BaseMstr.BaseData);

        status = data.UpdateChecklistItemLogic(
            ChecklistID,
            ChecklistItemID,
            txtItemLogic.Text);
        if (!status.Status)
        {
            return(status);
        }

        return(new CStatus());
    }
Exemplo n.º 12
0
    /// <summary>
    /// gets the item state id
    /// </summary>
    /// <param name="lCollItemID"></param>
    /// <param name="patItemDI"></param>
    /// <returns></returns>
    protected k_STATE_ID GetItemStateID(long lCollectionItemID,
                                        long lItemID,
                                        DataSet dsPatItemComps,
                                        CPatientItemDataItem patItemDI)
    {
        k_STATE_ID kStateID          = k_STATE_ID.Unknown;
        k_STATE_ID kOverallTSStateID = k_STATE_ID.NotSelected;
        k_STATE_ID kOverallOSStateID = k_STATE_ID.NotSelected;

        //get the entry date
        DateTime dtEntryDate = patItemDI.EntryDate;

        //get the checklist collection item di
        CChecklistItemDataItem cidDI = null;
        CChecklistItemData     cid   = new CChecklistItemData(BaseMstr.BaseData);

        cid.GetCLItemDI(ChecklistID, 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);

        //check the TS and set overall TS state
        k_COMPARE kTS = CDataUtils.CompareDates(dtEntryDate, dtTSCompare);

        if (kTS == k_COMPARE.GREATERTHAN ||
            kTS == k_COMPARE.EQUALTO)
        {
            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      = PatientID;
                    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(BaseMstr.BaseData);
            icd.GetICStateDI(lItemID, diPatItemComp.ComponentID, out sdi);

            //switch on the type and get the value
            switch ((k_ITEM_TYPE_ID)patItemDI.ItemTypeID)
            {
            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
                //and do not affect default logic. must use custom logic
                //for note titles
                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;
                }
                else
                {
                    kOverallOSStateID = k_STATE_ID.Good;
                }

                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 os state is unk
        //and ts state is bad!
        if (!bHasSelectedValue)
        {
            kOverallOSStateID = k_STATE_ID.Unknown;
            kOverallTSStateID = k_STATE_ID.Bad;
        }

        if (kOverallTSStateID == k_STATE_ID.Bad ||
            kOverallOSStateID == k_STATE_ID.Bad)
        {
            kStateID = k_STATE_ID.Bad;
        }
        else if (kOverallTSStateID == k_STATE_ID.Good &&
                 kOverallOSStateID == k_STATE_ID.Good)
        {
            kStateID = k_STATE_ID.Good;
        }
        else
        {
            kStateID = k_STATE_ID.Unknown;
        }

        return(kStateID);
    }
Exemplo n.º 13
0
    /// <summary>
    /// US:865 sets UI permssions based on the users role
    /// </summary>
    public void SetPermissions()
    {
        //do permissions work
        CChecklistPermissionsDataItem pdi = null;
        CChecklistData clData             = new CChecklistData(BaseMstr.BaseData);

        clData.GetCheckListPermissionsDI(ChecklistID, out pdi);

        //does the user have read only permissions to this checklist
        if (pdi.HasPermission(BaseMstr.AppUser, k_CHECKLIST_PERMISSION.ReadOnly))
        {
            foreach (GridViewRow gr in gvPatCLItems.Rows)
            {
                Button btnOR = (Button)gr.FindControl("btnOverride");
                if (btnOR != null)
                {
                    btnOR.Enabled = false;
                }

                Button btnED = (Button)gr.FindControl("btnEdit");
                if (btnED != null)
                {
                    btnED.Enabled = false;
                }
            }
        }
        else
        {
            //loop over the items and determine if the user is allowed to override
            //decision state for each item
            foreach (GridViewRow gr in gvPatCLItems.Rows)
            {
                if (gvPatCLItems.DataKeys[gr.RowIndex].Value != null)
                {
                    //get the item id
                    long lItemID = Convert.ToInt32(gvPatCLItems.DataKeys[gr.RowIndex].Value);

                    //load a item permissions data item
                    CChecklistItemPermissionsDataItem pi = null;
                    CChecklistItemData cli    = new CChecklistItemData(BaseMstr.BaseData);
                    CStatus            status = new CStatus();
                    status = cli.GetCLPermissionItem(ChecklistID,
                                                     lItemID,
                                                     out pi);
                    if (status.Status)
                    {
                        if (!pi.HasPermission(BaseMstr.AppUser,
                                              k_CHECKLIST_PERMISSION.DSOverride))
                        {
                            Button btnOR = (Button)gr.FindControl("btnOverride");
                            if (btnOR != null)
                            {
                                btnOR.Enabled = false;
                            }

                            Button btnED = (Button)gr.FindControl("btnEdit");
                            if (btnED != null)
                            {
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 14
0
    /// <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);
    }
    /// <summary>
    /// event
    /// US:902
    /// loads the action set state list box
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void OnSelIndexChangedActionSpecifier(object sender, EventArgs e)
    {
        ShowMPE();
        lbActionValue.Items.Clear();

        long lSpecifierValue = Convert.ToInt64(lbActionSpecifier.SelectedValue);

        if (lSpecifierValue != k_TEMPORAL_STATE &&
            lSpecifierValue != k_OUTCOME_STATE &&
            lSpecifierValue != k_DECISION_STATE)
        {
            return;
        }

        //get the cli data and check the checkboxes
        CChecklistItemData CLIData           = new CChecklistItemData(BaseMstr.BaseData);
        DataSet            ds                = null;
        string             strDataTextField  = string.Empty;
        string             strDataValueField = string.Empty;
        CStatus            status            = null;

        switch (lSpecifierValue)
        {
        case k_TEMPORAL_STATE:
            status            = CLIData.GetTemporalStateDS(ChecklistID, ChecklistItemID, out ds);
            strDataTextField  = "TS_LABEL";
            strDataValueField = "TS_ID";
            break;

        case k_OUTCOME_STATE:
            status            = CLIData.GetOutcomeStateDS(ChecklistID, ChecklistItemID, out ds);
            strDataTextField  = "OS_LABEL";
            strDataValueField = "OS_ID";
            break;

        case k_DECISION_STATE:
            status            = CLIData.GetDecisionStateDS(ChecklistID, ChecklistItemID, out ds);
            strDataTextField  = "DS_LABEL";
            strDataValueField = "DS_ID";
            break;
        }

        if (!status.Status)
        {
            ShowStatusInfo(status);
            return;
        }

        if (ds.Tables[0].Rows.Count > 0)
        {
            lbActionValue.DataTextField  = strDataTextField;
            lbActionValue.DataValueField = strDataValueField;
            lbActionValue.DataSource     = ds;
            lbActionValue.DataBind();
            lblActionValue.Visible = true;
            lbActionValue.Visible  = true;
        }
        else
        {
            lblActionValue.Visible = false;
            lbActionValue.Visible  = false;
        }
    }