Пример #1
0
        public void AddElement(DatasetElement datasetElement)
        {
            if (datasetElement == null)
            {
                throw new ArgumentNullException(nameof(datasetElement));
            }
            ;

            if (DatasetCategoryElements.Any(dce => dce.DatasetElement.Id == datasetElement.Id))
            {
                throw new Exception("Element has already been added");
            }

            var datasetCategoryElement = new DatasetCategoryElement()
            {
                DatasetCategory = this,
                Acute           = false,
                Chronic         = false,
                DatasetElement  = datasetElement,
                FieldOrder      = 1,
                FriendlyName    = string.Empty,
                Help            = string.Empty,
                Public          = false,
                System          = false
            };

            DatasetCategoryElements.Add(datasetCategoryElement);
        }
Пример #2
0
        private void MapValuesUsingInstance(DatasetCategoryElement dce, string tag, DatasetInstance sourceInstance)
        {
            var mapping = dce.DestinationMappings.SingleOrDefault(dm => dm.Tag == tag);

            if (mapping != null)
            {
                if (dce.DatasetElement.Field.FieldType.Description != "Table")
                {
                    var sourceValue = mapping.SourceElement != null?sourceInstance.GetInstanceValue(mapping.SourceElement.DatasetElement) : "";

                    if (!String.IsNullOrWhiteSpace(sourceValue))
                    {
                        var formattedValue = TranslateSourceValueForElement(mapping, sourceValue);

                        if (!String.IsNullOrWhiteSpace(formattedValue))
                        {
                            SetInstanceValue(dce.DatasetElement, formattedValue);
                        }
                    }
                }
                else
                {
                    // we need to process mapping using sub elements
                    var sourceContexts = sourceInstance.GetInstanceSubValuesContext(mapping.SourceElement.DatasetElement);
                    foreach (Guid sourceContext in sourceContexts)
                    {
                        var newContext    = Guid.NewGuid();
                        var subItemValues = sourceInstance.GetInstanceSubValues(mapping.SourceElement.DatasetElement, sourceContext);
                        foreach (DatasetMappingSub subMapping in mapping.SubMappings)
                        {
                            var sourceSubValue = subMapping.SourceElement != null?subItemValues.SingleOrDefault(siv => siv.DatasetElementSub.Id == subMapping.SourceElement.Id) : null;

                            if (sourceSubValue != null)
                            {
                                var formattedValue = TranslateSourceValueForSubElement(subMapping, sourceSubValue.InstanceValue);

                                if (!String.IsNullOrWhiteSpace(formattedValue))
                                {
                                    SetInstanceSubValue(subMapping.DestinationElement, formattedValue, newContext);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private void MapValuesUsingEvent(DatasetCategoryElement dce, string tag, PatientClinicalEvent clinicalEvent)
        {
            IExtendable ptExtended = clinicalEvent.Patient;
            IExtendable ceExtended = clinicalEvent;

            if (dce.DestinationMappings.Where(dm => dm.Tag == tag).Count() > 0)
            {
                // Get the value to be translated
                var    mapping     = dce.DestinationMappings.Single(dm => dm.Tag == tag);
                string sourceValue = string.Empty;
                object objectValue;

                if (mapping.MappingType == MappingType.AttributeToElement || mapping.MappingType == MappingType.AttributeToValue)
                {
                    if (!String.IsNullOrWhiteSpace(mapping.PropertyPath) && !String.IsNullOrWhiteSpace(mapping.Property))
                    {
                        switch (mapping.PropertyPath)
                        {
                        case "Patient":
                            objectValue = ptExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";

                            break;

                        case "PatientClinicalEvent":
                            objectValue = ceExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrWhiteSpace(mapping.Property))
                        {
                            objectValue = ceExtended.GetAttributeValue(mapping.Property);
                            sourceValue = objectValue != null?objectValue.ToString() : "";
                        }
                    }
                }
                else
                {
                    Object src = clinicalEvent;
                    if (mapping.MappingType == MappingType.FirstClassToElement || mapping.MappingType == MappingType.FirstClassToValue)
                    {
                        if (!String.IsNullOrWhiteSpace(mapping.PropertyPath))
                        {
                            switch (mapping.PropertyPath)
                            {
                            case "Patient":
                                src = clinicalEvent.Patient;
                                break;

                            default:
                                break;
                            }
                        }
                        objectValue = src.GetType().GetProperty(mapping.Property).GetValue(src, null);
                        sourceValue = objectValue != null?objectValue.ToString() : "";
                    }
                }

                // Translate the value
                if (!String.IsNullOrWhiteSpace(sourceValue))
                {
                    var formattedValue = TranslateSourceValueForElement(mapping, sourceValue);

                    if (!String.IsNullOrWhiteSpace(formattedValue))
                    {
                        SetInstanceValue(dce.DatasetElement, formattedValue);
                    }
                }
            }
        }