feature: RBAC + Clinical Audit Logging
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
public static class AuthHelper
|
||||
{
|
||||
public static void AsNurse(this HttpClient client, Guid? userId = null)
|
||||
{
|
||||
client.DefaultRequestHeaders.Remove("X-Test-Role");
|
||||
client.DefaultRequestHeaders.Add("X-Test-Role", "NURSE");
|
||||
if (userId.HasValue)
|
||||
{
|
||||
client.DefaultRequestHeaders.Remove("X-Test-User-Id");
|
||||
client.DefaultRequestHeaders.Add("X-Test-User-Id", userId.ToString()!);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AsAdmin(this HttpClient client) =>
|
||||
client.DefaultRequestHeaders.Add("X-Test-Role", "ADMIN");
|
||||
|
||||
public static void AsPhysician(this HttpClient client) =>
|
||||
client.DefaultRequestHeaders.Add("X-Test-Role", "PHYSICIAN");
|
||||
|
||||
public static void AsIntegration(this HttpClient client) =>
|
||||
client.DefaultRequestHeaders.Add("X-Test-Role", "INTEGRATION");
|
||||
|
||||
public static void ClearAuth(this HttpClient client)
|
||||
{
|
||||
client.DefaultRequestHeaders.Remove("X-Test-Role");
|
||||
client.DefaultRequestHeaders.Remove("X-Test-User-Id");
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ public static class DbResetHelper
|
||||
DELETE FROM external_resource_identifiers;
|
||||
DELETE FROM encounters;
|
||||
DELETE FROM alert_thresholds;
|
||||
DELETE FROM clinical_audit_logs;
|
||||
DELETE FROM clinical_users;
|
||||
DELETE FROM patients;
|
||||
");
|
||||
return;
|
||||
|
||||
@@ -90,7 +90,8 @@ public static class ScenarioReplayHelper
|
||||
public static async Task<SofaScore> WaitForSofaScoreAsync(
|
||||
IServiceProvider services,
|
||||
Guid encounterId,
|
||||
TimeSpan timeout)
|
||||
TimeSpan timeout,
|
||||
Func<SofaScore, bool>? predicate = null)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
while (DateTime.UtcNow < deadline)
|
||||
@@ -101,7 +102,7 @@ public static class ScenarioReplayHelper
|
||||
.Where(s => s.EncounterId == encounterId)
|
||||
.OrderByDescending(s => s.CalculatedAt)
|
||||
.FirstOrDefaultAsync();
|
||||
if (sofa is not null)
|
||||
if (sofa is not null && (predicate is null || predicate(sofa)))
|
||||
return sofa;
|
||||
await Task.Delay(500);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public static class TestAuthContext
|
||||
{
|
||||
public static void AsNurse(
|
||||
IServiceProvider services,
|
||||
Guid? userId = null,
|
||||
string displayName = "Test Nurse")
|
||||
{
|
||||
var accessor = services.GetRequiredService<IHttpContextAccessor>();
|
||||
var context = new DefaultHttpContext();
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
||||
new Claim(ClaimTypes.Name, "test-nurse"),
|
||||
new Claim("display_name", displayName),
|
||||
new Claim("clinical_role", "NURSE"),
|
||||
};
|
||||
context.User = new ClaimsPrincipal(new ClaimsIdentity(claims, TestingAuthHandler.SchemeName));
|
||||
accessor.HttpContext = context;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user