public void SetProperty_Observation_Value_Test3()
        {
            int value = 15;

            FHIRPropertyMapping mapping = new FHIRPropertyMapping()
            {
                ResourcePath      = "Observation/Value/Value",
                ResourcePathTypes = "Observation/SimpleQuantity/Decimal"
            };
            var o = SetProperty(mapping, value);

            Assert.IsTrue(o is Observation);
            Assert.IsTrue((o as Observation).Value is SimpleQuantity);
            Assert.AreEqual(((o as Observation).Value as SimpleQuantity).Value, value);
        }
        public void SetProperty_Period_Start_Test()
        {
            var value = "2020-01-01";

            FHIRPropertyMapping mapping = new FHIRPropertyMapping()
            {
                ResourcePath      = "ResearchSubject/Period/Start",
                ResourcePathTypes = "ResearchSubject/Period/String"
            };
            var o = SetProperty(mapping, value);

            Assert.IsTrue(o is ResearchSubject);
            Assert.IsFalse((o as ResearchSubject).Period is null);
            Assert.AreEqual(((o as ResearchSubject).Period).Start, value);
        }
        public void SetProperty_Observation_Value_Test2()
        {
            int value = 15;
            var o     = FHIRTranslator.CreateInstance("Hl7.Fhir.Model.Observation");

            FHIRPropertyMapping mapping = new FHIRPropertyMapping()
            {
                ResourcePath      = "Observation/Value/Value",
                ResourcePathTypes = "Observation/SimpleQuantity/Decimal"
            };

            SetProperty(o, mapping, value);
            Assert.IsTrue(o is Observation);
            Assert.IsTrue((o as Observation).Value is SimpleQuantity);
            Assert.AreEqual(((o as Observation).Value as SimpleQuantity).Value, value);
        }
        public void Parse_Test1()
        {
            FHIRParser parser       = new FHIRParser();
            var        propMapping1 = new FHIRPropertyMapping()
            {
                ColumnIndex       = 1,
                ResourceId        = "001001",
                ResourceBaseType  = "Observation",
                ResourcePath      = "Observation/Value/Value",
                ResourcePathTypes = "Observation/SimpleQuantity/Decimal",
                FixedProperties   = new List <FHIRProperty>()
                {
                    new FHIRProperty()
                    {
                        ResourcePath      = "Observation/Code/Text",
                        ResourcePathTypes = "Observation/CodeableConcept/String",
                        Value             = "Code1"
                    },
                    new FHIRProperty()
                    {
                        ResourcePath      = "Observation/Issued",
                        ResourcePathTypes = "Observation/DateTimeOffset",
                        Value             = "GETDATE"
                    }
                }
            };



            parser.Parse(null, "001", propMapping1, new CSVRow()
            {
                new CSVColumn()
                {
                    ColumnIndex = 1, Value = "1"
                }
            });

            var res = parser.GetResource("001001001");

            Assert.IsNotNull(res);

            Assert.AreEqual(((res as Observation).Value as SimpleQuantity).Value, 1);
        }
Exemple #5
0
        /// <summary>
        ///     Parse Row
        /// </summary>
        /// <param name="baseResourceId"></param>
        /// <param name="baseReferenceUrl"></param>
        /// <param name="prop"></param>
        /// <param name="columns"></param>
        public void Parse(string baseResourceId, string baseReferenceUrl, FHIRPropertyMapping prop, CSVRow columns)
        {
            //1. Find Column in the dataset
            CSVColumn column = null;

            if (prop.ColumnIndex.HasValue)
            {
                column = columns.Where(e => e.ColumnIndex.HasValue)
                         .FirstOrDefault(e => e.ColumnIndex.Value == prop.ColumnIndex.Value);
            }
            if (column == null && !string.IsNullOrEmpty(prop.ColumnName))
            {
                column = columns.FirstOrDefault(e => e.ColumnName == prop.ColumnName);
            }

            if (column == null)
            {
                throw new ArgumentNullException();
            }

            object root = null;


            if (string.IsNullOrEmpty(prop.ResourceBaseType))
            {
                throw new ResourceBaseTypeNotDefined();
            }


            //Get Base Resource Identifier based on base ResourceId and property Resource Id
            var resourceId = GetBaseResourceId(baseResourceId + prop.ResourceId, columns);

            //if the resource already exists then the property is assigned to the existing resource
            if (_resourceDictionary.ContainsKey(resourceId))
            {
                root = _resourceDictionary[resourceId].Item2;

                FHIRTranslator.SetProperty(root, prop.ResourcePath, column.Value, prop.ResourcePathTypes,
                                           prop.ValueTemplate);
            }
            else
            {
                //Create a new resource
                root = FHIRTranslator.SetProperty(prop.ResourcePath, prop.ResourcePathTypes, column.Value,
                                                  prop.ValueTemplate);

                //Set Resource Id
                if (root != null && root is Resource && string.IsNullOrEmpty((root as Resource).Id))
                {
                    (root as Resource).Id = resourceId;
                }

                // Add to resource dictionary with the corresponding resource URL for reference
                _resourceDictionary.Add(resourceId,
                                        Tuple.Create(prop.ResourceBaseType,
                                                     root,
                                                     GetUrl(baseReferenceUrl,
                                                            prop.ResourceBaseType,
                                                            root as Resource)));
            }

            //Create Fix properties on the Resource
            if (root != null && prop.FixedProperties != null)
            {
                CreateFixProperties(root, prop.FixedProperties, columns);
            }
        }
 private object SetProperty(FHIRPropertyMapping mapping, object value)
 {
     return(FHIRTranslator.SetProperty(mapping.ResourcePath, mapping.ResourcePathTypes, value));
 }
 private void SetProperty(object root, FHIRPropertyMapping mapping, object value)
 {
     FHIRTranslator.SetProperty(root, mapping.ResourcePath, value, mapping.ResourcePathTypes);
 }