Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Client/Services/DiscoveryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ public DiscoveryService(HttpClient httpClient, ILogger<DiscoveryService> logger)
/// <param name="community"></param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<MetadataVerificationModel?> GetUdapMetadataVerificationModel(string metadataUrl, string? community, CancellationToken token)
public Task<MetadataVerificationModel?> GetUdapMetadataVerificationModel(string metadataUrl, string? community, CancellationToken token) =>
GetUdapMetadataVerificationModel(metadataUrl, community, probe: false, token);

/// <inheritdoc />
public Task<MetadataVerificationModel?> ProbeUdapMetadata(string metadataUrl, CancellationToken token) =>
GetUdapMetadataVerificationModel(metadataUrl, null, probe: true, token);

private async Task<MetadataVerificationModel?> GetUdapMetadataVerificationModel(
string metadataUrl, string? community, bool probe, CancellationToken token)
{
try
{
Expand All @@ -46,6 +54,12 @@ public DiscoveryService(HttpClient httpClient, ILogger<DiscoveryService> logger)
{
var udapMetadataUrl = $"Metadata?metadataUrl={metadataUrl}";

if (probe)
{
// Validate without making this URL the session's FHIR server.
udapMetadataUrl += "&probe=true";
}

if (community != null)
{
udapMetadataUrl += $"&{UdapConstants.Community}={community}";
Expand Down
20 changes: 15 additions & 5 deletions Client/Services/FhirService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,27 @@ public async Task<FhirResultModel<Bundle>> SearchGet(string queryParameters)
{
var controller = await GetControllerPath();
var response = await _httpClient.PostAsJsonAsync($"{controller}/GetSearch", queryParameters);

return await SearchHandler(response);
var result = await SearchHandler(response);
EnrichResult(response, result);
return result;
}

public async Task<FhirResultModel<Bundle>> SearchPost(SearchForm searchForm)
{
var controller = await GetControllerPath();
var response = await _httpClient.PostAsJsonAsync($"{controller}/PostSearch", searchForm);

return await SearchHandler(response);
var result = await SearchHandler(response);
EnrichResult(response, result);
return result;
}

public async Task<FhirResultModel<Resource>> Get(string resourcePath)
{
var controller = await GetControllerPath();
var response = await _httpClient.PostAsJsonAsync($"{controller}/Get", resourcePath);
return await GetHandler(response);
var result = await GetHandler(response);
EnrichResult(response, result);
return result;
}

private async Task<FhirResultModel<Resource>> GetHandler(HttpResponseMessage response)
Expand Down Expand Up @@ -653,6 +657,12 @@ private void EnrichResult<T>(HttpResponseMessage responseMessage, FhirResultMode
}
}

if (responseMessage.Headers.TryGetValues(UdapEdConstants.FhirClient.FhirElapsedMs, out var elapsedValues)
&& long.TryParse(elapsedValues.FirstOrDefault(), out var elapsedMs))
{
resultModel.FhirElapsedMs = elapsedMs;
}

if (responseMessage.Headers.TryGetValues(UdapEdConstants.FhirClient.FhirOutgoingRequest, out var reqValues))
{
var base64 = reqValues.FirstOrDefault();
Expand Down
1 change: 0 additions & 1 deletion Client/wwwroot/Packages/udap_urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"https://dev-mtx-interop.meditech.com/v2/uscore/STU6",
"https://securefhir.zimt.work/udap-public",
"https://identity-matching.fast.hl7.org/fhir",
"https://national-directory.fast.hl7.org/fhir",
"https://udap.fhir.poolnook.me/evernorth",
"https://fhir-udap.azurewebsites.net",
"https://ihe-nimbus.epic.com/Interconnect-FHIR/api/fhir/r4"
Expand Down
18 changes: 9 additions & 9 deletions Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&display=swap" rel="stylesheet" />
<!-- These files have no fingerprint in their names and the CDN in front of the site caches them for an hour,
so each link carries ?v=<release>. Bump it every release, here and in the scripts below. -->
<link href="_content/MudBlazor/MudBlazor.min.css?v=0.9.2506" rel="stylesheet" />
<link href="_content/UdapEd.Shared/css/app.css?v=0.9.2506" rel="stylesheet" />
<link href="_content/UdapEd.Shared/css/cds.css?v=0.9.2506" rel="stylesheet" />
<link href="css/monaco.css?v=0.9.2506" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css?v=0.9.2507" rel="stylesheet" />
<link href="_content/UdapEd.Shared/css/app.css?v=0.9.2507" rel="stylesheet" />
<link href="_content/UdapEd.Shared/css/cds.css?v=0.9.2507" rel="stylesheet" />
<link href="css/monaco.css?v=0.9.2507" rel="stylesheet" />
<!-- <link href="UdapEd.Client.styles.css" rel="stylesheet" /> -->
</head>

Expand All @@ -44,12 +44,12 @@
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js?v=0.9.2506"></script>
<script src="_content/UdapEd.Shared/scripts/AutoFocus.js?v=0.9.2506"></script>
<script src="_content/UdapEd.Shared/scripts/UdapEdUtility.js?v=0.9.2506"></script>
<script src="_content/UdapEd.Shared/scripts/EventHandlers.js?v=0.9.2506"></script>
<script src="_content/MudBlazor/MudBlazor.min.js?v=0.9.2507"></script>
<script src="_content/UdapEd.Shared/scripts/AutoFocus.js?v=0.9.2507"></script>
<script src="_content/UdapEd.Shared/scripts/UdapEdUtility.js?v=0.9.2507"></script>
<script src="_content/UdapEd.Shared/scripts/EventHandlers.js?v=0.9.2507"></script>

<script src="_content/BlazorMonaco/jsInterop.js?v=0.9.2506"></script>
<script src="_content/BlazorMonaco/jsInterop.js?v=0.9.2507"></script>
<!-- The Monaco editor (about 1.4 MB) loads on first use: see udapEdMonaco.ensureLoaded in UdapEdUtility.js. -->

<!-- todo package in RCL -->
Expand Down
35 changes: 25 additions & 10 deletions Server/Controllers/FhirController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,13 @@ public async Task<IActionResult> GetSearch([FromBody] string fullSearch)
{
try
{
//Todo maybe inject in the future, so we don't exhaust underlying HttpClient
var httpClient = new HttpClient(_customDecompressionHandler);
using var httpClient = DirectoryHttpClient();
var fhirClient = new FhirClient(fullSearch, httpClient, new FhirClientSettings() { PreferredFormat = ResourceFormat.Json });

Console.WriteLine(fullSearch);
var bundle = await fhirClient.GetAsync(fullSearch);
var bundleJson = await new FhirJsonSerializer().SerializeToStringAsync(bundle);

CopyCustomHeadersToResponse();
return Ok(bundleJson);
}
catch (FhirOperationException ex)
Expand Down Expand Up @@ -402,20 +401,20 @@ public async Task<IActionResult> PostSearch([FromBody] SearchForm searchForm)
{
try
{
//Todo maybe inject in the future, so we don't exhaust underlying HttpClient
var httpClient = new HttpClient(_customDecompressionHandler);
using var httpClient = DirectoryHttpClient();
var fhirClient = new FhirClient(searchForm.Url, httpClient, new FhirClientSettings() { PreferredFormat = ResourceFormat.Json });
var searchParams = new SearchParams();

foreach (var pair in searchForm.FormUrlEncoded)
{
var item = pair.Split('=');
searchParams.Add(item[0], item[1]);
var item = pair.Split('=', 2);
searchParams.Add(item[0], item.Length > 1 ? item[1] : string.Empty);
}

var bundle = await fhirClient.SearchUsingPostAsync(searchParams, searchForm.Resource);
var bundleJson = await new FhirJsonSerializer().SerializeToStringAsync(bundle);

CopyCustomHeadersToResponse();
return Ok(bundleJson);
}
catch (FhirOperationException ex)
Expand Down Expand Up @@ -454,13 +453,13 @@ public async Task<IActionResult> Get([FromBody] string resourcePath)
{
try
{
var httpClient = new HttpClient(_customDecompressionHandler);
using var httpClient = DirectoryHttpClient();
var fhirClient = new FhirClient(resourcePath, httpClient, new FhirClientSettings() { PreferredFormat = ResourceFormat.Json });

Console.WriteLine(resourcePath);

var resource = await fhirClient.GetAsync(resourcePath);
var resourceJson = await new FhirJsonSerializer().SerializeToStringAsync(resource);

CopyCustomHeadersToResponse();
return Ok(resourceJson);
}
catch (FhirOperationException ex)
Expand Down Expand Up @@ -494,6 +493,22 @@ public async Task<IActionResult> Get([FromBody] string resourcePath)
}
}

/// <summary>
/// GetSearch, PostSearch and Get go to whatever absolute URL the page sends (a directory, its /metadata), so
/// they skip the session's FhirClientWithUrlProvider and its access token. This pipeline still asks for
/// compression and records the wire sizes, the outgoing request and the elapsed time for the page.
/// </summary>
private HttpClient DirectoryHttpClient()
{
var services = HttpContext.RequestServices;
var accessor = services.GetRequiredService<IHttpContextAccessor>();

return new HttpClient(new CustomDecompressionHandler(services.GetRequiredService<IFhirClientOptionsProvider>(), accessor)
{
InnerHandler = new RequestCaptureHandler(accessor) { InnerHandler = new HttpClientHandler() }
});
}

private void CopyCustomHeadersToResponse()
{
foreach (var kvp in HttpContext.Items.Where(i => i.Key is string key && key.StartsWith("X-")))
Expand Down
10 changes: 8 additions & 2 deletions Server/Controllers/MetadataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public MetadataController(IUdapClient udapClient, HttpClient httpClient, IOption

// get fully validated metadata from .well-known/udap
[HttpGet]
public async Task<IActionResult> Get([FromQuery] string metadataUrl, [FromQuery] string community)
// probe=true (the Directory page checking each Endpoint) validates without making metadataUrl the session's
// FHIR server, which Patient Search and the access token follow.
public async Task<IActionResult> Get([FromQuery] string metadataUrl, [FromQuery] string community, [FromQuery] bool probe = false)
{
var anchorString = HttpContext.Session.GetString(UdapEdConstants.UDAP_ANCHOR_CERTIFICATE);

Expand Down Expand Up @@ -83,7 +85,11 @@ public async Task<IActionResult> Get([FromQuery] string metadataUrl, [FromQuery]
// Show the metadata even when it failed validation, next to the problems found. The UdapClient keeps
// only validated metadata in UdapServerMetadata; the response carries what was downloaded.
result.UdapServerMetaData = _udapClient.UdapServerMetadata ?? response.UnvalidatedMetadata;
HttpContext.Session.SetString(UdapEdConstants.BASE_URL, metadataUrl);

if (!probe)
{
HttpContext.Session.SetString(UdapEdConstants.BASE_URL, metadataUrl);
}

return Ok(result);
}
Expand Down
13 changes: 12 additions & 1 deletion Server/Services/Fhir/RequestCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// */
#endregion

using System.Diagnostics;
using System.Text;
using System.Text.Json;
using UdapEd.Shared;
Expand Down Expand Up @@ -71,6 +72,16 @@ protected override async Task<HttpResponseMessage> SendAsync(
Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
}

return await base.SendAsync(request, cancellationToken);
// Time the call to the FHIR server alone: this handler is innermost, so the UdapEd hop is not counted.
var stopwatch = Stopwatch.StartNew();
var response = await base.SendAsync(request, cancellationToken);
stopwatch.Stop();

if (httpContext != null)
{
httpContext.Items[UdapEdConstants.FhirClient.FhirElapsedMs] = stopwatch.ElapsedMilliseconds.ToString();
}

return response;
}
}
10 changes: 6 additions & 4 deletions Shared/Components/FhirEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@
Language = _language,
GlyphMargin = false,
Value = _editorContent,
ShowFoldingControls = "false",
ShowFoldingControls = "always",
AutoDetectHighContrast = false,

// The editor can start inside a hidden tab; let Monaco track its container's size.
AutomaticLayout = true,
ReadOnly = true,
ScrollBeyondLastLine = false,
WordWrap = "on",
};
}

Expand All @@ -97,8 +101,6 @@
}

await UpdateTheme();
await _editor.Layout(new Dimension() { Height = 600, Width = 200 });
await JS.InvokeVoidAsync("setMonacoEditorResize", _editor.Id);
await _editor.SetValue(_editorContent ?? string.Empty);
}

Expand Down
Loading
Loading