/// <summary> </summary>
        protected override void DoWork(CodeActivityContext context)
        {
            Success.Set(context, true);

            var obrId = ObrId.Get(context);
            var dataItemThresholds = DataItemThresholds.Get(context);

            if (dataItemThresholds == null)
            {
                return;
            }

            ObsDef obsDefEntity = ObsDef.GetEntityByObdGuid(dataItemThresholds.ObdGuid, PM);

            if (obsDefEntity.IsNullEntity)
            {
                return;
            }

            var query = new EntityQuery(typeof(ObsReq));

            query.AddClause(ObsReqDataRow.OBR_IDEntityColumn, EntityQueryOp.EQ, obrId);
            var obsReqEntity = PM.GetEntity <ObsReq>(query);

            if (obsReqEntity.IsNullEntity)
            {
                return;
            }

            query = new EntityQuery(typeof(Observe));
            query.AddClause(ObserveDataRow.OBD_IDEntityColumn, EntityQueryOp.EQ, obsDefEntity.OBD_ID);
            query.AddClause(ObserveDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, obsReqEntity.Pat_ID1);
            query.AddClause(ObserveDataRow.OBR_SET_IDEntityColumn, EntityQueryOp.EQ, obsReqEntity.OBR_Set_ID);
            var observeEntity = PM.GetEntity <Observe>(query);

            if (observeEntity.IsNullEntity)
            {
                return;
            }

            var success = CommonCharting.CheckDataItemThresholds(observeEntity, dataItemThresholds);

            Success.Set(context, success);
        }
        private void CloseDialog()
        {
            ObsDef obd = null;

            if (buttonDataItem.Tag != null)
            {
                obd = buttonDataItem.Tag as ObsDef;
            }

            if (obd != null)
            {
                Value         = new DataItemThresholds();
                Value.ObdGuid = obd.OBD_GUID;

                if (obd.Type == (short)MedDefs.ObdType.ItemTable)
                {
                    Value.TableItems = new List <Guid>();
                    foreach (CheckedListBoxItem item in comboTableItems.Properties.Items)
                    {
                        if (item.CheckState != CheckState.Checked)
                        {
                            continue;
                        }

                        var obdGuid = (Guid)item.Value;
                        if (obdGuid != Guid.Empty)
                        {
                            Value.TableItems.Add(obdGuid);
                        }
                    }
                }
                else if (obd.Type == (short)MedDefs.ObdType.ItemData)
                {
                    double d;
                    switch (obd.ObsDefDataFormat)
                    {
                    case ObsDefDataFormat.Numeric:
                        if (Double.TryParse(textLowerLimit.Text, out d))
                        {
                            Value.LowerLimit = d;
                        }
                        if (Double.TryParse(textUpperLimit.Text, out d))
                        {
                            Value.UpperLimit = d;
                        }
                        break;

                    case ObsDefDataFormat.Date:
                        Value.DateRange = inputDateRange.DateRange;
                        Value.StartDate = inputDateRange.DateRange.StartDate;
                        if (Value.StartDate == DateTime.MinValue)
                        {
                            Value.StartDate = null;
                        }
                        Value.EndDate = inputDateRange.DateRange.EndDate;
                        if (Value.EndDate == DateTime.MaxValue)
                        {
                            Value.EndDate = null;
                        }
                        break;

                    case ObsDefDataFormat.String:
                    case ObsDefDataFormat.Memo:
                        int algorithmId = comboStringAlgorithm.SelectedIndex >= 0 ? comboStringAlgorithm.SelectedIndex : 0;
                        Value.StringAlgorithm = _stringAlgoriths[algorithmId];
                        if (UseStringNumericLimits(Value.StringAlgorithm))
                        {
                            if (Double.TryParse(textLowerLimit.Text, out d))
                            {
                                Value.LowerLimit = d;
                            }
                            if (Double.TryParse(textUpperLimit.Text, out d))
                            {
                                Value.UpperLimit = d;
                            }
                        }
                        else
                        {
                            Value.StringInput = textStringInput.Text;
                        }
                        break;
                    }
                }
            }

            ValidateChildren();
            DialogResult = DialogResult.OK;
            Close();
        }