public void TestNonExistingPropertyReturnsNull() { var index = new FhirPropertyIndex(_fhirModel, new List<Type> { typeof(Patient), typeof(Account) }); var pm = index.findPropertyInfo("TypeNotPresent", "subject"); Assert.IsNull(pm); pm = index.findPropertyInfo("Patient", "property_not_present"); Assert.IsNull(pm); }
public void TestExistingPropertyIsFound() { var index = new FhirPropertyIndex(_fhirModel, new List<Type> { typeof(Patient), typeof(HumanName) }); var pm = index.findPropertyInfo("Patient", "name"); Assert.IsNotNull(pm); pm = index.findPropertyInfo("HumanName", "given"); Assert.IsNotNull(pm); }
public void TestTypedNameIsFound() { var index = new FhirPropertyIndex(_fhirModel, new List<Type> { typeof(ClinicalImpression) }); var pm = index.findPropertyInfo("ClinicalImpression", "triggerCodeableConcept"); Assert.IsNotNull(pm); }
/// <summary> /// Walk through an object, following the specified path of properties. /// The path should NOT include the name of the resource itself (e.g. "Patient.birthdate" is wrong, "birthdate" is right). /// </summary> /// <param name="fhirObject"></param> /// <param name="action"></param> /// <param name="path"></param> /// <param name="predicate"></param> public void VisitByPath(object fhirObject, Action <object> action, string path, string predicate = null) { if (fhirObject == null) { return; } //List of items, visit each of them. if (TestIfGenericList(fhirObject.GetType())) { VisitByPath(fhirObject as IEnumerable <Base>, action, path, predicate); } //Single item, visit it if it adheres to the predicate (if any) else if (String.IsNullOrEmpty(predicate) || PredicateIsTrue(predicate, fhirObject)) { //Path has ended, we arrived at the object that needs action. if (String.IsNullOrEmpty(path)) { action(fhirObject); } //See what else is in the path and recursively visit that. else { var hpt = headPredicateAndTail(path); var head = hpt.Item1; var headPredicate = hpt.Item2; var tail = hpt.Item3; //Path was not empty, so there should be a head. No need for an extra null-check. var pm = _propIndex.findPropertyInfo(fhirObject.GetType(), head); //Path might denote an unknown property. if (pm != null) { var headValue = pm.PropInfo.GetValue(fhirObject); if (headValue != null) { VisitByPath(headValue, action, tail, headPredicate); } } else { //TODO: Throw exception (Spark.Exception.NotSupportedException for example), to be catched higher up and then translated to the OperationOutcome. } } } }