private void ButtonCheckExpression_Click(object sender, RoutedEventArgs e) { EvaluationContext evalContext; var inputNav = GetResourceNavigator(out evalContext); if (inputNav == null) { return; } // Don't need to cache this, it is cached in the fhir-client Hl7.FhirPath.Expressions.Expression expr = null; try { expr = FhirPathProcessor._compiler.Parse(textboxExpression.Text); } catch (Exception ex) { SetResults("Expression compilation error:\r\n" + ex.Message, true); return; } if (expr != null) { try { FhirPathProcessor.CheckExpression(inputNav, expr, AppendResults, ResetResults); } catch (Exception ex) { SetResults("Expression Check error:\r\n" + ex.Message, true); return; } } }
private void ButtonGo_Click(object sender, RoutedEventArgs e) { EvaluationContext evalContext; var inputNav = GetResourceNavigator(out evalContext); if (inputNav == null) { return; } // Don't need to cache this, it is cached in the fhir-client CompiledExpression xps = null; try { xps = FhirPathProcessor._compiler.Compile(textboxExpression.Text); } catch (Exception ex) { SetResults("Expression compilation error:\r\n" + ex.Message, true); return; } IEnumerable <ITypedElement> prepopulatedValues = null; if (xps != null) { try { prepopulatedValues = xps(inputNav, evalContext); } catch (Exception ex) { SetResults("Expression evaluation error:\r\n" + ex.Message); AppendParseTree(); return; } ResetResults(); AddHistoryEntry(textboxInputXML.Text, textboxExpression.Text); try { FhirPathProcessor.ProcessPrepopulatedValues(prepopulatedValues, AppendXmlFramentResults, AppendResults); } catch (Exception ex) { SetResults("Processing results error:\r\n" + ex.Message); return; } } AppendParseTree(); }
public MainPage() { this.InitializeComponent(); TextControlFontSize = 22; textboxInputXML.Text = "<Patient xmlns=\"http://hl7.org/fhir\">\r\n <name>\r\n <given value=\"brian\"/>\r\n </name>\r\n <birthDate value=\"1980\"/>\r\n</Patient>"; textboxExpression.Text = "birthDate < today()"; DataContext = this; // and remember the initial state AddHistoryEntry(textboxInputXML.Text, textboxExpression.Text); System.Threading.Tasks.Task.Run(() => { // in the background load up the 3 sets of ClassLibraries r4.Hl7.Fhir.Serialization.BaseFhirParser.Inspector.Import(typeof(r4.Hl7.Fhir.Serialization.BaseFhirParser).Assembly); // stu3.Hl7.Fhir.Serialization.BaseFhirParser.Inspector.Import(typeof(stu3.Hl7.Fhir.Serialization.BaseFhirParser).Assembly); dstu2.Hl7.Fhir.Serialization.BaseFhirParser.Inspector.Import(typeof(dstu2.Hl7.Fhir.Serialization.BaseFhirParser).Assembly); FhirPathProcessor.GetResourceNavigatorSTU3("<Patient xmlns=\"http://hl7.org/fhir\"/>", out var errs); }); }
private ITypedElement GetResourceNavigator(out EvaluationContext evalContext) { string parseErrors2; var inputNavDSTU2 = FhirPathProcessor.GetResourceNavigatorDSTU2(textboxInputXML.Text, out parseErrors2); string parseErrors3; var inputNavSTU3 = FhirPathProcessor.GetResourceNavigatorSTU3(textboxInputXML.Text, out parseErrors3); string parseErrors4; var inputNavR4 = FhirPathProcessor.GetResourceNavigatorR4(textboxInputXML.Text, out parseErrors4); if (!string.IsNullOrEmpty(parseErrors2) || !string.IsNullOrEmpty(parseErrors3) || !string.IsNullOrEmpty(parseErrors4)) { ResetResults(); AppendResults(String.Join("\r\n--------------------\r\n", parseErrors2, parseErrors3, parseErrors4), true); } if (inputNavR4 != null || inputNavSTU3 != null || inputNavDSTU2 != null) { ISourceNode node; if (textboxInputXML.Text.StartsWith("{")) { node = Hl7.Fhir.Serialization.FhirJsonNode.Parse(textboxInputXML.Text); } else { node = Hl7.Fhir.Serialization.FhirXmlNode.Parse(textboxInputXML.Text); } _locations.Clear(); int lastPos = 0; IPositionInfo lastNode = null; AddLocations(node, ref lastNode, ref lastPos, textboxInputXML.Text.ToCharArray()); string t = _locations.LastOrDefault(c => c.Key < textboxInputXML.SelectionStart).Value; System.Diagnostics.Trace.WriteLine($"Focused: {t}"); } if (inputNavR4 != null) { btnR4.Visibility = Visibility.Visible; } else { btnR4.Visibility = Visibility.Collapsed; } if (inputNavSTU3 != null) { btnSTU3.Visibility = Visibility.Visible; } else { btnSTU3.Visibility = Visibility.Collapsed; } if (inputNavDSTU2 != null) { btnDSTU2.Visibility = Visibility.Visible; } else { btnDSTU2.Visibility = Visibility.Collapsed; } if (inputNavR4 != null) { evalContext = new fp4.FhirEvaluationContext(inputNavR4); return(inputNavR4); } if (inputNavSTU3 != null) { evalContext = new fp3.FhirEvaluationContext(inputNavSTU3); return(inputNavSTU3); } evalContext = new fp2.FhirEvaluationContext(inputNavDSTU2); return(inputNavDSTU2); }
private void BtnJson_Click(object sender, RoutedEventArgs e) { FhirPathProcessor.PretifyJson(textboxInputXML.Text, (val) => { textboxInputXML.Text = val; }); }
private async void textboxInputXML_Drop(object sender, DragEventArgs e) { try { // This is the place where we want to support the reading of the file from the file system // to make the testing of other instances really easy if (e.DataView != null) { var formats = e.DataView.AvailableFormats; if (formats.Contains(StandardDataFormats.WebLink)) { Uri webLink = await e.DataView.GetWebLinkAsync(); if (!string.IsNullOrEmpty(webLink.OriginalString)) { using (HttpClient client = new HttpClient()) { using (var response = await client.GetAsync(webLink)) { string contents = await response.Content.ReadAsStringAsync(); textboxInputXML.Text = contents; if (response.Content.Headers.ContentType.MediaType.Contains("xml")) { FhirPathProcessor.PretifyXML(textboxInputXML.Text, (val) => { textboxInputXML.Text = val; }); } if (response.Content.Headers.ContentType.MediaType.Contains("json")) { FhirPathProcessor.PretifyJson(textboxInputXML.Text, (val) => { textboxInputXML.Text = val; }); } AddHistoryEntry(textboxInputXML.Text, textboxExpression.Text); } } } e.Handled = true; return; } if (formats.Contains(StandardDataFormats.StorageItems)) { var items = await e.DataView.GetStorageItemsAsync(); if (items.Count > 0) { if (items[0].IsOfType(StorageItemTypes.File)) { string contents = await FileIO.ReadTextAsync((StorageFile)items[0]); textboxInputXML.Text = contents; AddHistoryEntry(textboxInputXML.Text, textboxExpression.Text); } } e.Handled = true; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }