Пример #1
0
        private void Apply(ItemUpdatedEvent itemUpdatedEvent)
        {
            var itemInstance = ItemInstances.FirstOrDefault(ii => ii.ItemDefinitionCode == itemUpdatedEvent.ItemDefinitionCode);
            var isNull       = itemUpdatedEvent.Value == null || string.IsNullOrEmpty(itemUpdatedEvent.Value.ToString());

            if (itemInstance != null && isNull)
            {
                _itemInstances.Remove(itemInstance);
            }

            if (itemInstance == null)
            {
                itemInstance = new ItemInstance(itemUpdatedEvent.ItemDefinitionCode, itemUpdatedEvent.Value, itemUpdatedEvent.IsRequired);
                if (!isNull)
                {
                    _itemInstances.Add(itemInstance);
                }
            }
            else
            {
                itemInstance.Apply(itemUpdatedEvent);
            }

            var skippingContext = new SkippingContext();

            if (_cachedRuleEngineExecutor == null)
            {
                var assessmentRuleCollectionFactory = new AssessmentRuleCollectionFactory();
                _cachedRuleEngineExecutor = new RuleEngineExecutor <AssessmentInstance> (
                    this,
                    assessmentRuleCollectionFactory.CreateRuleCollection(this.AssessmentName));
            }
            _cachedRuleEngineExecutor
            .ForRuleSet("ItemUpdatedRuleSet" + itemInstance.ItemDefinitionCode)
            .WithContext(itemInstance, itemInstance.ItemDefinitionCode)
            .WithContext(skippingContext)
            .Execute();

            skippingContext.SkippedItemDefinitions.ForEach(
                item =>
            {
                if (item.GetIsRequired() && !_skippedItemDefinitions.Contains(item))
                {
                    _skippedItemDefinitions.Add(item);
                }
                if (ItemInstances.Any(i => i.ItemDefinitionCode == item.CodedConcept.Code))
                {
                    UpdateItem(item, null);
                }
            });
            skippingContext.UnSkippedItemDefinitions.ForEach(item => _skippedItemDefinitions.Remove(item));
        }
Пример #2
0
        private void Apply(ItemUpdatedEvent itemUpdatedEvent)
        {
            var itemInstance = ItemInstances.FirstOrDefault(ii => ii.ItemDefinitionCode == itemUpdatedEvent.ItemDefinitionCode);

            if (itemInstance == null)
            {
                _itemInstances.Add(new ItemInstance(itemUpdatedEvent.ItemDefinitionCode, itemUpdatedEvent.Value));
            }
            else
            {
                itemInstance.Apply(itemUpdatedEvent);
            }
        }