Example #1
0
    /// <summary>
    /// method
    /// US:902
    /// returns the attribute specified for the most recent patient item identified by the patient id and item id
    /// </summary>
    /// <param name="strPatientID"></param>
    /// <param name="lItemID"></param>
    /// <param name="strSpecifier"></param>
    /// <returns></returns>
    private CStringStatus ParsePatItem(string strPatientID, long lItemID, string strSpecifier)
    {
        CPatientItemData     PatientItem = new CPatientItemData(BaseData);
        CPatientItemDataItem di          = null;
        CStatus status = PatientItem.GetMostRecentPatientItemDI(strPatientID, lItemID, out di);

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

        string strValue = CExpression.NullTkn;

        switch (strSpecifier)
        {
        case "date":
            strValue = (CDataUtils.IsDateNull(di.EntryDate)) ? CExpression.NullTkn : CExpression.DateTkn + di.EntryDate.ToString() + CExpression.DateTkn;
            break;

        case "source":
            strValue = (di.SourceTypeID < 1) ? CExpression.NullTkn : di.SourceTypeID.ToString();
            break;

        case "exists":
            strValue = (di.PatItemID < 1) ? false.ToString() : true.ToString();
            break;
        }

        return(new CStringStatus(status, strValue));
    }
Example #2
0
    /// <summary>
    /// method
    /// loads all of the patient's items into the specified ddl
    /// for the specified item
    /// </summary>
    /// <param name="BaseMstr"></param>
    /// <param name="ddl"></param>
    /// <returns></returns>
    public static CStatus LoadPatientItemsDDL(
        CData Data,
        DropDownList ddl,
        string strPatientID,
        long lItemID)
    {
        CPatientItemData dta     = new CPatientItemData(Data);
        DataSet          dsItems = null;
        CStatus          status  = dta.GetPatientItemDS(
            strPatientID,
            lItemID,
            out dsItems);

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

        status = CDropDownList.RenderDataSet(
            dsItems,
            ddl,
            "ENTRY_DATE",
            "PAT_ITEM_ID");
        if (!status.Status)
        {
            return(status);
        }

        return(new CStatus());
    }
Example #3
0
    /// <summary>
    /// US:1945 US:1880 load control
    /// </summary>
    /// <param name="lEditMode"></param>
    /// <returns></returns>
    public override CStatus LoadControl(k_EDIT_MODE lEditMode)
    {
        EditMode = lEditMode;

        tbNoteTitle.Text = string.Empty;

        CPatientItemData     PatientItemData = new CPatientItemData(BaseMstr.BaseData);
        CPatientItemDataItem di = null;

        CStatus status = new CStatus();

        //if no pat item id then load the most recent
        if (PatientItemID < 1)
        {
            status = PatientItemData.GetMostRecentPatientItemDI(PatientID,
                                                                ItemID,
                                                                out di);
            if (!status.Status)
            {
                return(status);
            }
        }
        else
        {
            status = PatientItemData.GetPatientItemDI(PatientID,
                                                      ItemID,
                                                      PatientItemID,
                                                      out di);
            if (!status.Status)
            {
                return(status);
            }
        }

        if (string.IsNullOrEmpty(di.PatientID))
        {
            return(new CStatus());
        }

        DataSet ds = null;

        status = PatientItemData.GetPatientItemComponentDS(di.PatientID, di.PatItemID, di.ItemID, out ds);
        if (!status.Status)
        {
            return(status);
        }

        tbNoteTitle.Text = di.ItemLabel + "\r\n";
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            tbNoteTitle.Text += dr["ITEM_COMPONENT_LABEL"].ToString() + "\r\n";
            tbNoteTitle.Text += dr["COMPONENT_VALUE"].ToString() + "\r\n";
        }

        tbNoteTitle.Text += "\r\n";

        return(new CStatus());
    }
    protected CStatus LoadPatComponents()
    {
        CPatientItemData pid     = new CPatientItemData(BaseMstr.BaseData);
        DataSet          dsComps = null;
        CStatus          status  = pid.GetPatientItemComponentDS(
            PatientID,
            Convert.ToInt64(ddlItems.SelectedValue),
            ItemID,
            out dsComps);

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

        DataTable dtComps = dsComps.Tables[0];

        if (dtComps == null || dtComps.Rows.Count != gvComponents.Rows.Count)
        {
            return(new CStatus(false, k_STATUS_CODE.Failed, "TODO"));
        }

        foreach (GridViewRow gvr in gvComponents.Rows)
        {
            RadioButton rbSelect = (RadioButton)gvr.FindControl("rbSelComponent");
            TextBox     txtVal   = (TextBox)gvr.FindControl("txtValue");
            if (rbSelect == null || txtVal == null)
            {
                return(new CStatus(false, k_STATUS_CODE.Failed, "TODO"));
            }

            DataRow drComp = dtComps.Select("ITEM_COMPONENT_ID = " + gvComponents.DataKeys[gvr.DataItemIndex][nItemComponentIDIndex].ToString())[0];
            switch ((k_ITEM_TYPE_ID)ItemTypeID)
            {
            case k_ITEM_TYPE_ID.Laboratory:
                txtVal.Text = drComp["COMPONENT_VALUE"].ToString();
                break;

            case k_ITEM_TYPE_ID.QuestionFreeText:
                txtVal.Text = drComp["COMPONENT_VALUE"].ToString();
                break;

            case k_ITEM_TYPE_ID.QuestionSelection:
                rbSelect.Checked = (drComp["COMPONENT_VALUE"].ToString() == "1") ? true : false;
                break;

            default:
                return(new CStatus(false, k_STATUS_CODE.Failed, "TODO"));
            }
        }

        return(new CStatus());
    }
Example #5
0
    public override CStatus LoadControl(k_EDIT_MODE lEditMode)
    {
        Title = "Item History";

        CItemData     id     = new CItemData(BaseMstr.BaseData);
        CItemDataItem diItem = null;
        CStatus       status = id.GetItemDI(ItemID, out diItem);

        if (!status.Status)
        {
            return(status);
        }
        hItem.InnerText = diItem.ItemLabel;

        CPatientItemData pid   = new CPatientItemData(BaseMstr.BaseData);
        DataSet          dsPIC = null;

        status = pid.GetPatItemCompDS(PatientID, ItemID, out dsPIC);
        if (!status.Status)
        {
            return(status);
        }
        PatientItemComponents = dsPIC.Tables[0];

        CItemComponentData icd  = new CItemComponentData(BaseMstr.BaseData);
        DataSet            dsIC = null;

        status = icd.GetItemComponentOJDS(ItemID, k_ACTIVE_ID.Active, out dsIC);
        if (!status.Status)
        {
            return(status);
        }

        ItemComponents = dsIC.Tables[0];
        if (ItemComponents.Rows.Count > 1)
        {
            pnlComponents.Visible    = true;
            rblComponents.DataSource = ItemComponents;
            rblComponents.DataBind();
            DataRow rdItemComponent = ItemComponents.Rows[0];
            rblComponents.SelectedValue = rdItemComponent["item_component_id"].ToString();
            GraphItemComponent(rdItemComponent);
        }
        else
        {
            pnlComponents.Visible = false;
            GraphItemComponent(ItemComponents.Rows[0]);
        }

        return(new CStatus());
    }
    /// <summary>
    ///US:1883 Abstract save control method
    /// </summary>
    /// <returns></returns>
    public override CStatus SaveControl()
    {
        CPatientItemData itemData   = new CPatientItemData(BaseMstr.BaseData);
        CStatus          status     = new CStatus();
        long             lPatItemID = -1;

        if (ddlItems.SelectedItem.Text == "[New Result]")
        {
            //load an item for insert
            CPatientItemDataItem di = new CPatientItemDataItem();
            di.PatientID    = PatientID;
            di.ItemID       = ItemID;
            di.SourceTypeID = (long)k_SOURCE_TYPE_ID.VAPPCT;

            //get the date time, which is a combination of the 2 controls
            di.EntryDate = CDataUtils.GetDate(txtEntryDate.Text, ucTimePicker.HH, ucTimePicker.MM, ucTimePicker.SS);

            // build a list of all the item components in the grid view
            CPatientItemCompList PatItemCompList = null;
            status = BuildPatItemCompList(out PatItemCompList);
            if (!status.Status)
            {
                return(status);
            }

            // insert the patient item and all of its item components
            status = itemData.InsertPatientItem(di, PatItemCompList, out lPatItemID);
            if (!status.Status)
            {
                return(status);
            }
        }
        else
        {
            lPatItemID = CDropDownList.GetSelectedLongID(ddlItems);
        }

        // update the comments if there is a new one
        if (!string.IsNullOrEmpty(txtComment.Text))
        {
            status = itemData.InsertPatientItemComment(lPatItemID, ItemID, txtComment.Text);
            if (!status.Status)
            {
                return(status);
            }
        }

        //show status
        return(new CStatus());
    }
    protected CStatus LoadPatItemAndComponents()
    {
        CPatientItemData     dta = new CPatientItemData(BaseMstr.BaseData);
        CPatientItemDataItem di  = null;
        CStatus status           = dta.GetPatientItemDI(
            PatientID,
            ItemID,
            Convert.ToInt64(ddlItems.SelectedValue),
            out di);

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

        // set date/time
        txtEntryDate.Text         = CDataUtils.GetDateAsString(di.EntryDate);
        calEntryDate.SelectedDate = di.EntryDate;
        ucTimePicker.SetTime(di.EntryDate);

        if (di.ItemTypeID == (long)k_ITEM_TYPE_ID.NoteTitle)
        {
            ucNoteTitle.ItemID        = di.ItemID;
            ucNoteTitle.PatientItemID = Convert.ToInt64(ddlItems.SelectedValue);
            ucNoteTitle.PatientID     = PatientID;
            status = ucNoteTitle.LoadControl(k_EDIT_MODE.UPDATE);
            if (!status.Status)
            {
                return(status);
            }
        }
        else
        {
            status = LoadPatComponents();
            if (!status.Status)
            {
                return(status);
            }
        }

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

        return(new CStatus());
    }
Example #8
0
    /// <summary>
    /// method
    /// US:902
    /// returns the worst state of the patient's item's components
    /// </summary>
    /// <param name="strPatientID"></param>
    /// <param name="lItemID"></param>
    /// <param name="strSpecifier"></param>
    /// <returns></returns>
    private CStringStatus ParsePICSummaryState(string strPatientID, long lItemID, string strSpecifier)
    {
        CPatientItemData PatientItem     = new CPatientItemData(BaseData);
        long             lSummaryStateID = -1;
        CStatus          status          = PatientItem.GetMostRecentPICSummaryStateID(
            strPatientID,
            lItemID,
            out lSummaryStateID);

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

        string strValue = (lSummaryStateID < 1) ? CExpression.NullTkn : lSummaryStateID.ToString();

        return(new CStringStatus(status, strValue));
    }
    protected CStatus LoadPatComments()
    {
        CPatientItemData itemData   = new CPatientItemData(BaseMstr.BaseData);
        DataSet          dsComments = null;
        CStatus          status     = itemData.GetPatientItemCommmentDS(
            Convert.ToInt64(ddlItems.SelectedValue),
            ItemID,
            out dsComments);

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

        gvComments.DataSource = dsComments;
        gvComments.DataBind();

        return(new CStatus());
    }
Example #10
0
    /// <summary>
    /// runs logic for a collection item this is na for now!
    /// too many issues to do this. ON hOLD!
    /// </summary>
    /// <param name="strPatientID"></param>
    /// <param name="lPatCLID"></param>
    /// <param name="lChecklistID"></param>
    /// <param name="lItemID"></param>
    /// <returns></returns>
    public CStatus RunCollectionLogic(string strPatientID,
                                      long lPatCLID,
                                      long lChecklistID,
                                      long lItemID)
    {
        CStatus status = new CStatus();

        DataSet dsColItems = null;

        CItemCollectionData icd = new CItemCollectionData(this);

        icd.GetItemCollectionDS(lItemID, out dsColItems);
        foreach (DataRow drItem in dsColItems.Tables[0].Rows)
        {
            try
            {
                //get the item type id
                long lColItemID = Convert.ToInt64(drItem["ITEM_ID"]);

                long             lSummaryStateID = -1;
                CPatientItemData pid             = new CPatientItemData(this);
                pid.GetMostRecentPICSummaryStateID(strPatientID,
                                                   lColItemID,
                                                   out lSummaryStateID);

                CPatientItemDataItem di = null;
                pid.GetMostRecentPatientItemDI(strPatientID,
                                               lColItemID,
                                               out di);
            }
            catch (Exception)
            {
                return(new CStatus(
                           false,
                           k_STATUS_CODE.Failed,
                           LogicModuleMessages.ERROR_RUN_LOGIC));
            }
        }

        return(status);
    }
Example #11
0
    /// <summary>
    /// method
    /// US:902
    /// returns the attribute specified by the specifier for the patient item component
    /// specified by the patient id, item id and item component id
    /// </summary>
    /// <param name="strPatientID"></param>
    /// <param name="lItemID"></param>
    /// <param name="lItemComponentID"></param>
    /// <param name="strSpecifier"></param>
    /// <returns></returns>
    private CStringStatus ParsePatItemComp(string strPatientID, long lItemID, long lItemComponentID, string strSpecifier)
    {
        CStatus status = null;

        CPatientItemData PatientItem            = new CPatientItemData(BaseData);
        CPatientItemComponentDataItem diPatItem = null;

        status = PatientItem.GetMostRecentPatientItemCompDI(strPatientID, lItemID, lItemComponentID, out diPatItem);
        if (!status.Status)
        {
            return(new CStringStatus(status, CExpression.NullTkn));
        }

        string strValue = CExpression.NullTkn;

        switch (strSpecifier)
        {
        case "value":
            strValue = (string.IsNullOrEmpty(diPatItem.ComponentValue)) ? CExpression.NullTkn : diPatItem.ComponentValue;
            break;
        }

        CItemData     Item   = new CItemData(BaseData);
        CItemDataItem diItem = null;

        status = Item.GetItemDI(lItemID, out diItem);
        if (!status.Status)
        {
            return(new CStringStatus(status, CExpression.NullTkn));
        }

        if (diItem.ItemTypeID != (long)k_ITEM_TYPE_ID.Laboratory)
        {
            strValue = CExpression.StringTkn + strValue + CExpression.StringTkn;
        }

        return(new CStringStatus(status, strValue));
    }
Example #12
0
    /// <summary>
    /// load a gridview value row
    /// </summary>
    /// <param name="gvr"></param>
    protected void LoadGridViewValue(GridViewRow gvr)
    {
        if (gvr == null)
        {
            return;
        }

        Panel pnlComponents = (Panel)gvr.FindControl("pnlComponents");
        Panel pnlViewValue  = (Panel)gvr.FindControl("pnlViewValue");

        if (pnlComponents == null || pnlViewValue == null)
        {
            return;
        }

        //hide the components, show the value view
        pnlComponents.Visible = false;
        pnlViewValue.Visible  = true;

        //literal that holds status info
        Literal litHiddenCollValues = (Literal)gvr.FindControl("litHiddenCollValues");

        litHiddenCollValues.Text = String.Empty;

        //button to expand/collapse
        Button btnShowHiddenCollValues = (Button)gvr.FindControl("btnShowHiddenCollValues");

        //get the gridview data row
        DataRowView drv = (DataRowView)gvr.DataItem;
        DataRow     dr  = drv.Row;

        //get the item type is and item id
        long lItemTypeID = Convert.ToInt64(dr["ITEM_TYPE_ID"]);
        long lItemID     = Convert.ToInt64(dr["ITEM_ID"]);

        //hide the expand/collapse if this is not a collection
        if (lItemTypeID != (long)k_ITEM_TYPE_ID.Collection)
        {
            AjaxControlToolkit.CollapsiblePanelExtender cpe = (AjaxControlToolkit.CollapsiblePanelExtender)gvr.FindControl("cpeHiddenCollValues");
            cpe.CollapseControlID = null;
            cpe.Enabled           = false;

            btnShowHiddenCollValues.Visible = false;
        }

        //if this is a collection, build a status summary list of each ite,
        if (lItemTypeID == (long)k_ITEM_TYPE_ID.Collection)
        {
            btnShowHiddenCollValues.Visible = true;

            //get all the patient item components in the collection
            CItemCollectionData coll           = new CItemCollectionData(BaseMstr.BaseData);
            DataSet             dsPatItemComps = null;
            coll.GetItemColMostRecentPatICDS(lItemID, PatientID, out dsPatItemComps);

            //get all the items in the collection
            DataSet dsColl = null;
            CStatus status = coll.GetItemCollectionDS(lItemID, out dsColl);

            //html to hold the status
            StringBuilder sbItemCompCollHTML = new StringBuilder();

            //loop over all the items in the collection and build html
            foreach (DataTable tableColl in dsColl.Tables)
            {
                foreach (DataRow drColl in tableColl.Rows)
                {
                    //get values from the the item in the collection (not the patient items, the collection items)
                    long lActiveID   = CDataUtils.GetDSLongValue(drColl, "ACTIVE_ID");
                    long lCollItemID = CDataUtils.GetDSLongValue(drColl, "ITEM_ID");

                    //get the item so we can check entry date against TS etc...
                    CPatientItemDataItem patItemDI = null;
                    CPatientItemData     patData   = new CPatientItemData(BaseMstr.BaseData);
                    patData.GetMostRecentPatientItemDI(PatientID, lCollItemID, out patItemDI);

                    //only interested in ACTIVE items
                    if ((k_ACTIVE)lActiveID == k_ACTIVE.ACTIVE)
                    {
                        //image for state open the img tag
                        sbItemCompCollHTML.Append("<img alt=\"");
                        //sbItemCompCollHTML.Append(CDataUtils.GetDSStringValue(dr, "ITEM_LABEL"));
                        sbItemCompCollHTML.Append(" Collection Item State Image\" width=\"10\" height=\"10\" src=\"");

                        //get the current state of the item
                        k_STATE_ID lItemStateID = GetItemStateID(lItemID, lCollItemID, dsPatItemComps, patItemDI);

                        //add a red/green/yellow image based on the state of the item
                        if (lItemStateID == k_STATE_ID.Unknown ||
                            lItemStateID == k_STATE_ID.NotSelected)
                        {
                            sbItemCompCollHTML.Append(Resources.Images.STATE_UNKNOWN_SMALL);
                        }
                        else if (lItemStateID == k_STATE_ID.Good)
                        {
                            sbItemCompCollHTML.Append(Resources.Images.STATE_GOOD_SMALL);
                        }
                        else
                        {
                            sbItemCompCollHTML.Append(Resources.Images.STATE_BAD_SMALL);
                        }

                        //close out the image tag
                        sbItemCompCollHTML.Append("\" />");

                        //label, trunc so it displays nicely
                        string strLabel = CDataUtils.GetDSStringValue(drColl, "ITEM_LABEL");
                        if (strLabel.Length > 28)
                        {
                            strLabel = strLabel.Substring(0, 28) + "...";
                        }

                        //add the label after the image
                        sbItemCompCollHTML.Append(strLabel);

                        //add a line break
                        sbItemCompCollHTML.Append("<br>");
                    }
                }
            }

            //set the literal equal to the generated html
            litHiddenCollValues.Text = sbItemCompCollHTML.ToString();

            //enable the show/hide button
            btnShowHiddenCollValues.Enabled = (String.IsNullOrEmpty(litHiddenCollValues.Text)) ? false : btnShowHiddenCollValues.Enabled;
        }
    }
    /// <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);
    }
Example #15
0
    /// <summary>
    /// US:1880 gets the most recent result, loops over all components and pieces together a string
    /// </summary>
    /// <param name="pid"></param>
    /// <param name="pidi"></param>
    /// <param name="strResult"></param>
    /// <returns></returns>
    public CStatus GetMostRecentResult(out string strResult)
    {
        strResult = string.Empty;

        //load the last result for this item
        CPatientItemData     pid  = new CPatientItemData(BaseMstr.BaseData);
        CPatientItemDataItem pidi = new CPatientItemDataItem();
        CStatus status            = pid.GetMostRecentPatientItemDI(PatientID, ItemID, out pidi);

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

        if (pidi.PatItemID < 1)
        {
            return(new CStatus());
        }

        DataSet dsComps = null;

        status = pid.GetPatientItemComponentDS(
            PatientID,
            pidi.PatItemID,
            pidi.ItemID,
            out dsComps);
        if (!status.Status)
        {
            return(status);
        }

        foreach (DataRow row in dsComps.Tables[0].Rows)
        {
            string strLabel = CDataUtils.GetDSStringValue(row, "item_component_label");
            string strValue = CDataUtils.GetDSStringValue(row, "component_value");
            string strUnits = CDataUtils.GetDSStringValue(row, "units");

            string strWarning = String.Empty;

            //question selection
            if (pidi.ItemTypeID == (long)k_ITEM_TYPE_ID.QuestionSelection)
            {
                if (strValue == "1")
                {
                    strResult += "<font face=\"verdana,arial\" size=\"-1\">";
                    strResult += strLabel;
                    strResult += "<br /></font>";
                }
            }

            //question free text
            else if (pidi.ItemTypeID == (long)k_ITEM_TYPE_ID.QuestionFreeText)
            {
                strResult += "<font face=\"verdana,arial\" size=\"-1\">";
                strResult += strLabel;
                strResult += ": ";
                strResult += strValue;
                strResult += "<br /></font>";
            }

            //lab
            else if (pidi.ItemTypeID == (long)k_ITEM_TYPE_ID.Laboratory)
            {
                if (CDataUtils.IsNumeric(strValue))
                {
                    double dblLegalMin     = CDataUtils.GetDSDoubleValue(row, "LEGAL_MIN");
                    double dblLow          = CDataUtils.GetDSDoubleValue(row, "LOW");
                    double dblCritialLow   = CDataUtils.GetDSDoubleValue(row, "CRITICAL_LOW");
                    double dblHigh         = CDataUtils.GetDSDoubleValue(row, "HIGH");
                    double dblCriticalHigh = CDataUtils.GetDSDoubleValue(row, "CRITICAL_HIGH");
                    double dblLegalMax     = CDataUtils.GetDSDoubleValue(row, "LEGAL_MAX");

                    double dblValue = Convert.ToDouble(strValue);
                    if (dblValue < dblLegalMin)
                    {
                        strWarning = "LESS THAN LEGAL MIN";
                    }
                    else if (dblValue < dblCritialLow)
                    {
                        strWarning = "CRITICAL LOW";
                    }
                    else if (dblValue < dblLow)
                    {
                        strWarning = "LOW";
                    }
                    else if (dblValue > dblLegalMax)
                    {
                        strWarning = "GREATER THAN LEGAL MAX";
                    }
                    else if (dblValue > dblCriticalHigh)
                    {
                        strWarning = "CRITICAL HIGH";
                    }
                    else if (dblValue > dblHigh)
                    {
                        strWarning = "HIGH";
                    }
                }

                strResult += "<font face=\"verdana,arial\" size=\"-1\">";
                strResult += strLabel;
                strResult += ": ";
                strResult += strValue;
                strResult += " ";
                strResult += strUnits;
                strResult += " ";
                strResult += strWarning;
                strResult += "<br /></font>";

                string strLegalMin     = CDataUtils.GetDSStringValue(row, "LEGAL_MIN");
                string strLow          = CDataUtils.GetDSStringValue(row, "LOW");
                string strCritialLow   = CDataUtils.GetDSStringValue(row, "CRITICAL_LOW");
                string strHigh         = CDataUtils.GetDSStringValue(row, "HIGH");
                string strCriticalHigh = CDataUtils.GetDSStringValue(row, "CRITICAL_HIGH");
                string strLegalMax     = CDataUtils.GetDSStringValue(row, "LEGAL_MAX");

                strResult += "<font face=\"verdana,arial\" size=\"-2\">";
                strResult += "(Legal Min: " + strLegalMin + " ";
                strResult += "Low: " + strLow + " ";
                strResult += "Critical Low: " + strCritialLow + " ";
                strResult += "High: " + strHigh + " ";
                strResult += "Critical High: " + strCriticalHigh + " ";
                strResult += "Legal Max: " + strLegalMax + ") ";
                strResult += "<br /><br /></font>";
            }
        }

        return(new CStatus());
    }