public void CreateInstance_CreateResearchSubject_Test() { var name = GetTypeName <ResearchSubject>(); Assert.AreEqual(name, "Hl7.Fhir.Model.ResearchSubject"); var o = FHIRTranslator.CreateInstance(name); Assert.IsNotNull(o); }
public void SetProperty_ResearchSubject_ID_Test() { var o = FHIRTranslator.CreateInstance("Hl7.Fhir.Model.ResearchSubject"); FHIRTranslator.SetProperty(o, "SUB001", "Id", "SUB001"); Assert.IsTrue(o is ResearchSubject); Assert.AreEqual((o as ResearchSubject).Id, "SUB001"); }
public void AssignValue_DateTimeOffset_Test() { TestObject obj = new TestObject(); var p = obj.GetType().GetProperty("DateTimeOffsetProp"); FHIRTranslator.AssignValue(p, obj, (long)15, "DateTimeOffset"); Assert.AreEqual(obj.DateTimeOffsetProp.Second, 15); }
public void AssignValue_Double_Test() { TestObject obj = new TestObject(); var p = obj.GetType().GetProperty("DoubleProp"); FHIRTranslator.AssignValue(p, obj, 15, "Double"); Assert.AreEqual(obj.DoubleProp, 15); }
public void SetProperty_ResearchSubject_Period_Start_Test() { string value = "2018/01/01"; var o = FHIRTranslator.CreateInstance("Hl7.Fhir.Model.ResearchSubject"); FHIRTranslator.SetProperty(o, "XX", "Period/Start", value); Assert.IsTrue(o is ResearchSubject); Assert.AreEqual((o as ResearchSubject).Period.Start, value); }
public void CreateFixPropertiesTest() { List <FHIRProperty> fixedProperties = new List <FHIRProperty>(); var o = FHIRTranslator.CreateInstance("Hl7.Fhir.Model.Observation"); fixedProperties.Add(new FHIRProperty() { ResourcePath = "Code/Text", Value = "Test", ResourcePathTypes = "CodeableConcept/String" }); FHIRParser.CreateFixProperties(o, fixedProperties); Assert.AreEqual((o as Observation).Code.Text, "Test"); }
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 static void CreateFixProperties(object root, IEnumerable <FHIRProperty> fixProps, List <CSVColumn> columns = null) { if (root == null) { throw new ArgumentNullException(); } if (fixProps == null) { throw new ArgumentNullException(); } //Add to object (FHIR Resource) all fixed properties foreach (var c in fixProps) { FHIRTranslator.SetProperty(root, c.ResourcePath, ConvertValue(c.Value, columns), c.ResourcePathTypes); } }
/// <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); }