Intergrating Attcius in a .NET frontend
Atticus can be integrated in .NET that use Windows Forms, WPF, or UWP. This page focuses on the UI integration in .NET applications. The technology used for this integration is WebView2, a browser control that renders web applications in .NET applications.
Prerequisites
Before you start integrating Atticus in your .NET application, make sure you have the following prerequisites:
Set up the WebView2 control
To get started with integrating Atticus in your .NET application, follow these steps:
-
Create a new .NET Windows Forms application in Visual Studio.
-
Add the necessary NuGet packages to your project:
- Microsoft.Web.WebView2
- Newtonsoft.Json
-
Add the webview control to your form in the designer:
-
Drag a WebView2 control from the toolbox to your form. See the Microsoft docs for more information
-
Initialize the WebView2 control in the form constructor:
public Form1() { InitializeComponent(); InitializeWebView2Async(); async void InitializeAsync() { await webView.EnsureCoreWebView2Async(null); await createSession(); } async Task createSession() { // Here comes the code to create a session } }
Create an authenticated session
The integration follows the Session Management flow: your application creates a session in the background with a POST request authenticated by your API key, then hands the returned one-time handover_token to the WebView2 control, which activates the session and receives the session cookie. The end-user is identified in the request body — via the user field or a fhirContext entry of type Practitioner.
Here is an example of how to create a session in a .NET application:
-
Create the session from your application code (not inside the WebView) using
HttpClient:string clientId = Environment.GetEnvironmentVariable("CLIENT_ID"); string clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET"); var client = new HttpClient(); var credentials = Convert.ToBase64String( Encoding.ASCII.GetBytes($"{clientId}:{clientSecret}")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); var payload = new { scope = "patient/QuestionnaireResponse.write patient/Patient.read patient/Encounter.read", patient = patientId, // FHIR Patient.id encounter = encounterId, // FHIR Encounter.id (optional) fhirContext = new object[] { new { identifier = new { system = "http://myhospital.org/user-ids", value = userIdentifier }, type = "Practitioner", role = "https://tiro.health/fhir/role/new" } } }; var response = await client.PostAsJsonAsync("https://auth.tiro.health/sessions", payload); var session = await response.Content.ReadFromJsonAsync<JsonElement>(); string handoverToken = session.GetProperty("handover_token").GetString(); -
Hand the token over to the WebView2 control by navigating it to the handover URL. The
nextvalue is the Launch URL the user should land on:string nextUrl = Uri.EscapeDataString("https://app.tiro.health/external/v1?task=Task/123"); webView.CoreWebView2.Navigate( $"https://auth.tiro.health/sessions/$handover?token={handoverToken}&next={nextUrl}");The handover endpoint activates the session, sets the session cookie in the WebView, and redirects to the
nextURL.
After completing these steps, you should have a working WebView2 control that can be used to display the Atticus Filler UI in your .NET application.