private static void ExtractExamplesFromResource(Dictionary <string, int> exampleSearchValues, Resource resource, ModelInfo.SearchParamDefinition index, string key) { var resourceModel = new FhirPath.PocoNavigator(resource); var navigator = new FhirPath.PocoNavigator(resource); try { var results = resourceModel.Select(index.Expression, navigator); if (results.Count() > 0) { foreach (var t2 in results) { if (t2 != null) { if (t2 is FhirPath.PocoNavigator && (t2 as FhirPath.PocoNavigator).FhirValue != null) { // Validate the type of data returned against the type of search parameter // Debug.Write(index.Resource + "." + index.Name + ": "); // Debug.WriteLine((t2 as FhirPath.ModelNavigator).FhirValue.ToString());// + "\r\n"; exampleSearchValues[key]++; } else if (t2.Value is Hl7.FhirPath.ConstantValue) { // Debug.Write(index.Resource + "." + index.Name + ": "); // Debug.WriteLine((t2.Value as Hl7.FhirPath.ConstantValue).Value); exampleSearchValues[key]++; } else if (t2.Value is bool) { // Debug.Write(index.Resource + "." + index.Name + ": "); // Debug.WriteLine((bool)t2.Value); exampleSearchValues[key]++; } else { Debug.Write(index.Resource + "." + index.Name + ": "); Debug.WriteLine(t2.Value); exampleSearchValues[key]++; } } } } } catch (ArgumentException ex) { Debug.WriteLine("FATAL: Error parsing expression in search index {0}.{1} {2}\r\n\t{3}", index.Resource, index.Name, index.Expression, ex.Message); } }
public void ValidateInvariants(OperationOutcome result) { if (InvariantConstraints != null && InvariantConstraints.Count > 0) { var sw = System.Diagnostics.Stopwatch.StartNew(); // Need to serialize to XML until the object model processor exists // string tpXml = Fhir.Serialization.FhirSerializer.SerializeResourceToXml(this); // FhirPath.IFhirPathElement tree = FhirPath.InstanceTree.TreeConstructor.FromXml(tpXml); var tree = new FhirPath.PocoNavigator(this); foreach (var invariantRule in InvariantConstraints) { ValidateInvariantRule(invariantRule, tree, result); } sw.Stop(); // System.Diagnostics.Trace.WriteLine(String.Format("Validation of {0} execution took {1}", ResourceType.ToString(), sw.Elapsed.TotalSeconds)); } }