Implement US-04 structured measurement context recording
This commit is contained in:
1 parent
5996481081
commit
cfacaa0c24
13 files changed
+646
-5
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using ObservationService.Contracts;
|
using ObservationService.Contracts;
|
||||||
using ObservationService.Domain;
|
using ObservationService.Domain;
|
||||||
@@ -26,6 +27,14 @@ public sealed class ObservationApplicationService(ObservationRepository reposito
|
|||||||
request.Diastolic is null or <= 0 || request.Pulse is null or <= 0)
|
request.Diastolic is null or <= 0 || request.Pulse is null or <= 0)
|
||||||
throw new ArgumentException("A timestamp and positive measured values are required.", nameof(request));
|
throw new ArgumentException("A timestamp and positive measured values are required.", nameof(request));
|
||||||
|
|
||||||
|
var suppliedContext = request.MeasurementContext ?? new MeasurementContext();
|
||||||
|
var measurementContext = suppliedContext with
|
||||||
|
{
|
||||||
|
Setting = suppliedContext.Setting ?? "Unknown",
|
||||||
|
ActivityCondition = suppliedContext.ActivityCondition ?? "Unknown"
|
||||||
|
};
|
||||||
|
Validator.ValidateObject(measurementContext, new ValidationContext(measurementContext), validateAllProperties: true);
|
||||||
|
|
||||||
using var patient = await clients.CreateClient("ApiGateway").GetAsync($"api/patients/{patientId}",
|
using var patient = await clients.CreateClient("ApiGateway").GetAsync($"api/patients/{patientId}",
|
||||||
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
if (patient.StatusCode == HttpStatusCode.NotFound)
|
if (patient.StatusCode == HttpStatusCode.NotFound)
|
||||||
@@ -44,6 +53,7 @@ public sealed class ObservationApplicationService(ObservationRepository reposito
|
|||||||
MeasuredAt = DateTime.SpecifyKind(measuredAt, DateTimeKind.Unspecified),
|
MeasuredAt = DateTime.SpecifyKind(measuredAt, DateTimeKind.Unspecified),
|
||||||
Systolic = request.Systolic.Value, Diastolic = request.Diastolic.Value,
|
Systolic = request.Systolic.Value, Diastolic = request.Diastolic.Value,
|
||||||
Pulse = request.Pulse.Value, Context = request.Context, Note = request.Note,
|
Pulse = request.Pulse.Value, Context = request.Context, Note = request.Note,
|
||||||
|
MeasurementContext = measurementContext,
|
||||||
CreatedAt = now, UpdatedAt = now
|
CreatedAt = now, UpdatedAt = now
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using ObservationService.Domain;
|
||||||
|
|
||||||
namespace ObservationService.Contracts;
|
namespace ObservationService.Contracts;
|
||||||
|
|
||||||
public sealed record ObservationDto(Guid ObservationId, Guid PatientId, DateTime MeasuredAt,
|
public sealed record ObservationDto(Guid ObservationId, Guid PatientId, DateTime MeasuredAt,
|
||||||
int Systolic, int Diastolic, int Pulse, string? Context, string? Note);
|
int Systolic, int Diastolic, int Pulse, string? Context, string? Note, MeasurementContext MeasurementContext);
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using ObservationService.Domain;
|
||||||
|
|
||||||
namespace ObservationService.Contracts;
|
namespace ObservationService.Contracts;
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ public sealed record RecordObservationRequest
|
|||||||
[Required, Range(1, int.MaxValue)]
|
[Required, Range(1, int.MaxValue)]
|
||||||
public int? Pulse { get; init; }
|
public int? Pulse { get; init; }
|
||||||
|
|
||||||
|
public MeasurementContext? MeasurementContext { get; init; }
|
||||||
|
|
||||||
public string? Context { get; init; }
|
public string? Context { get; init; }
|
||||||
public string? Note { get; init; }
|
public string? Note { get; init; }
|
||||||
}
|
}
|
||||||
@@ -76,5 +76,5 @@ public sealed class ObservationController(ObservationApplicationService service)
|
|||||||
|
|
||||||
private static ObservationDto ToDto(BloodPressureObservation observation) =>
|
private static ObservationDto ToDto(BloodPressureObservation observation) =>
|
||||||
new(observation.ObservationId, observation.PatientId, observation.MeasuredAt, observation.Systolic,
|
new(observation.ObservationId, observation.PatientId, observation.MeasuredAt, observation.Systolic,
|
||||||
observation.Diastolic, observation.Pulse, observation.Context, observation.Note);
|
observation.Diastolic, observation.Pulse, observation.Context, observation.Note, observation.MeasurementContext);
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ public sealed class BloodPressureObservation
|
|||||||
public int Systolic { get; set; }
|
public int Systolic { get; set; }
|
||||||
public int Diastolic { get; set; }
|
public int Diastolic { get; set; }
|
||||||
public int Pulse { get; set; }
|
public int Pulse { get; set; }
|
||||||
|
public MeasurementContext MeasurementContext { get; set; } = new();
|
||||||
public string? Context { get; set; }
|
public string? Context { get; set; }
|
||||||
public string? Note { get; set; }
|
public string? Note { get; set; }
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace ObservationService.Domain;
|
||||||
|
|
||||||
|
public sealed record MeasurementContext
|
||||||
|
{
|
||||||
|
[AllowedValues("Home", "Clinic", "Other", "Unknown", null)]
|
||||||
|
public string? Setting { get; init; } = "Unknown";
|
||||||
|
|
||||||
|
[AllowedValues("AtRest", "DuringActivity", "AfterActivity", "Unknown", null)]
|
||||||
|
public string? ActivityCondition { get; init; } = "Unknown";
|
||||||
|
|
||||||
|
[Range(0, double.MaxValue)]
|
||||||
|
public decimal? RestDurationMinutes { get; init; }
|
||||||
|
|
||||||
|
public string? BodyPosition { get; init; }
|
||||||
|
public string? MeasuredArm { get; init; }
|
||||||
|
public string? DeviceDetails { get; init; }
|
||||||
|
public string? CuffDetails { get; init; }
|
||||||
|
public string? AdditionalCircumstances { get; init; }
|
||||||
|
}
|
||||||
Generated
+134
@@ -0,0 +1,134 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using ObservationService.Persistence;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ObservationService.Persistence.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ObservationDbContext))]
|
||||||
|
[Migration("20261005094632_RecordedMeasurementContext")]
|
||||||
|
partial class RecordedMeasurementContext
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.12")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("ObservationService.Domain.BloodPressureObservation", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("ObservationId")
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("observation_id");
|
||||||
|
|
||||||
|
b.Property<string>("Context")
|
||||||
|
.HasColumnType("character varying")
|
||||||
|
.HasColumnName("context");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp without time zone")
|
||||||
|
.HasColumnName("created_at");
|
||||||
|
|
||||||
|
b.Property<int>("Diastolic")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("diastolic");
|
||||||
|
|
||||||
|
b.Property<DateTime>("MeasuredAt")
|
||||||
|
.HasColumnType("timestamp without time zone")
|
||||||
|
.HasColumnName("measured_at");
|
||||||
|
|
||||||
|
b.Property<string>("Note")
|
||||||
|
.HasColumnType("character varying")
|
||||||
|
.HasColumnName("note");
|
||||||
|
|
||||||
|
b.Property<Guid>("PatientId")
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("patient_id");
|
||||||
|
|
||||||
|
b.Property<int>("Pulse")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("pulse");
|
||||||
|
|
||||||
|
b.Property<int>("Systolic")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("systolic");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp without time zone")
|
||||||
|
.HasColumnName("updated_at");
|
||||||
|
|
||||||
|
b.HasKey("ObservationId");
|
||||||
|
|
||||||
|
b.ToTable("blood_pressure_observation", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ObservationService.Domain.BloodPressureObservation", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("ObservationService.Domain.MeasurementContext", "MeasurementContext", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("BloodPressureObservationObservationId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<string>("ActivityCondition")
|
||||||
|
.IsRequired()
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasDefaultValue("Unknown")
|
||||||
|
.HasColumnName("activity_condition");
|
||||||
|
|
||||||
|
b1.Property<string>("AdditionalCircumstances")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("additional_circumstances");
|
||||||
|
|
||||||
|
b1.Property<string>("BodyPosition")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("body_position");
|
||||||
|
|
||||||
|
b1.Property<string>("CuffDetails")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("cuff_details");
|
||||||
|
|
||||||
|
b1.Property<string>("DeviceDetails")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("device_details");
|
||||||
|
|
||||||
|
b1.Property<string>("MeasuredArm")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("measured_arm");
|
||||||
|
|
||||||
|
b1.Property<decimal?>("RestDurationMinutes")
|
||||||
|
.HasColumnType("numeric")
|
||||||
|
.HasColumnName("rest_duration_minutes");
|
||||||
|
|
||||||
|
b1.Property<string>("Setting")
|
||||||
|
.IsRequired()
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasDefaultValue("Unknown")
|
||||||
|
.HasColumnName("setting");
|
||||||
|
|
||||||
|
b1.HasKey("BloodPressureObservationObservationId");
|
||||||
|
|
||||||
|
b1.ToTable("blood_pressure_observation");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("BloodPressureObservationObservationId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("MeasurementContext")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ObservationService.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RecordedMeasurementContext : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "activity_condition",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "Unknown");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "additional_circumstances",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "body_position",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "cuff_details",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "device_details",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "measured_arm",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<decimal>(
|
||||||
|
name: "rest_duration_minutes",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "numeric",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "setting",
|
||||||
|
table: "blood_pressure_observation",
|
||||||
|
type: "text",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "activity_condition",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "additional_circumstances",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "body_position",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "cuff_details",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "device_details",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "measured_arm",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "rest_duration_minutes",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "setting",
|
||||||
|
table: "blood_pressure_observation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,6 +68,63 @@ namespace ObservationService.Persistence.Migrations
|
|||||||
|
|
||||||
b.ToTable("blood_pressure_observation", (string)null);
|
b.ToTable("blood_pressure_observation", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ObservationService.Domain.BloodPressureObservation", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("ObservationService.Domain.MeasurementContext", "MeasurementContext", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("BloodPressureObservationObservationId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<string>("ActivityCondition")
|
||||||
|
.IsRequired()
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasDefaultValue("Unknown")
|
||||||
|
.HasColumnName("activity_condition");
|
||||||
|
|
||||||
|
b1.Property<string>("AdditionalCircumstances")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("additional_circumstances");
|
||||||
|
|
||||||
|
b1.Property<string>("BodyPosition")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("body_position");
|
||||||
|
|
||||||
|
b1.Property<string>("CuffDetails")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("cuff_details");
|
||||||
|
|
||||||
|
b1.Property<string>("DeviceDetails")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("device_details");
|
||||||
|
|
||||||
|
b1.Property<string>("MeasuredArm")
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasColumnName("measured_arm");
|
||||||
|
|
||||||
|
b1.Property<decimal?>("RestDurationMinutes")
|
||||||
|
.HasColumnType("numeric")
|
||||||
|
.HasColumnName("rest_duration_minutes");
|
||||||
|
|
||||||
|
b1.Property<string>("Setting")
|
||||||
|
.IsRequired()
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("text")
|
||||||
|
.HasDefaultValue("Unknown")
|
||||||
|
.HasColumnName("setting");
|
||||||
|
|
||||||
|
b1.HasKey("BloodPressureObservationObservationId");
|
||||||
|
|
||||||
|
b1.ToTable("blood_pressure_observation");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("BloodPressureObservationObservationId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("MeasurementContext")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ public sealed class ObservationDbContext(DbContextOptions<ObservationDbContext>
|
|||||||
observation.Property(o => o.Pulse).HasColumnName("pulse");
|
observation.Property(o => o.Pulse).HasColumnName("pulse");
|
||||||
observation.Property(o => o.Context).HasColumnName("context").HasColumnType("character varying");
|
observation.Property(o => o.Context).HasColumnName("context").HasColumnType("character varying");
|
||||||
observation.Property(o => o.Note).HasColumnName("note").HasColumnType("character varying");
|
observation.Property(o => o.Note).HasColumnName("note").HasColumnType("character varying");
|
||||||
|
observation.OwnsOne(o => o.MeasurementContext, context =>
|
||||||
|
{
|
||||||
|
context.Property(c => c.Setting).HasColumnName("setting").HasDefaultValue("Unknown").IsRequired();
|
||||||
|
context.Property(c => c.ActivityCondition).HasColumnName("activity_condition").HasDefaultValue("Unknown").IsRequired();
|
||||||
|
context.Property(c => c.RestDurationMinutes).HasColumnName("rest_duration_minutes");
|
||||||
|
context.Property(c => c.BodyPosition).HasColumnName("body_position");
|
||||||
|
context.Property(c => c.MeasuredArm).HasColumnName("measured_arm");
|
||||||
|
context.Property(c => c.DeviceDetails).HasColumnName("device_details");
|
||||||
|
context.Property(c => c.CuffDetails).HasColumnName("cuff_details");
|
||||||
|
context.Property(c => c.AdditionalCircumstances).HasColumnName("additional_circumstances");
|
||||||
|
});
|
||||||
|
observation.Navigation(o => o.MeasurementContext).IsRequired();
|
||||||
observation.Property(o => o.CreatedAt).HasColumnName("created_at").HasColumnType("timestamp without time zone");
|
observation.Property(o => o.CreatedAt).HasColumnName("created_at").HasColumnType("timestamp without time zone");
|
||||||
observation.Property(o => o.UpdatedAt).HasColumnName("updated_at").HasColumnType("timestamp without time zone");
|
observation.Property(o => o.UpdatedAt).HasColumnName("updated_at").HasColumnType("timestamp without time zone");
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-3
@@ -64,9 +64,51 @@ the account’s profile when its generated identifier is not yet known.
|
|||||||
|
|
||||||
`PUT /api/patients/{patientId}` updates the name and contact information and returns `200` with the updated profile. It preserves the patient identifier, date of birth and creation timestamp, and updates the modification timestamp. Names must be nonblank, consistent with profile creation; omitted or null contact information clears that optional value. A missing patient returns `404` without creating a profile. Invalid requests return `400` without changing stored information.
|
`PUT /api/patients/{patientId}` updates the name and contact information and returns `200` with the updated profile. It preserves the patient identifier, date of birth and creation timestamp, and updates the modification timestamp. Names must be nonblank, consistent with profile creation; omitted or null contact information clears that optional value. A missing patient returns `404` without creating a profile. Invalid requests return `400` without changing stored information.
|
||||||
|
|
||||||
`POST /api/patients/{patientId}/observations` records a blood-pressure observation. Supply `measuredAt`, positive integer `systolic`, `diastolic` and `pulse`, plus optional `context` and `note`. It returns `201`, the saved observation including its generated `observationId` and `patientId`, and `Location: /api/observations/{observationId}`. `GET` at that location retrieves the persisted observation, or returns `404` if absent. Retrieval is included to satisfy US-04's requirement that a recorded observation can be retrieved later.
|
`POST /api/patients/{patientId}/observations` records a blood-pressure observation. Supply `measuredAt`, positive integer `systolic`, `diastolic` and `pulse`, plus optional `measurementContext`, legacy `context` and `note`. It returns `201`, the saved observation including its generated `observationId` and `patientId`, and `Location: /api/observations/{observationId}`. `GET` at that location retrieves the persisted observation, or returns `404` if absent. Retrieval is included to satisfy US-04's requirement that a recorded observation can be retrieved later.
|
||||||
|
|
||||||
The Observation Service checks patient existence by calling the gateway's patient retrieval API over HTTP before saving. It has no reference to Patient/Profile implementation code and no access to that service's database. Missing patients return `404`; validation failures return `400`. Patient lookup failures return `502` or `504` and do not save an observation. Measurement timestamps without an offset are stored as supplied; timestamps with an offset are normalized to UTC. PostgreSQL uses the diagram's `timestamp` columns without a time-zone component.
|
US-04 now supports structured context independently of legacy free text:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"measuredAt": "2026-09-12T08:00:00Z",
|
||||||
|
"systolic": 128,
|
||||||
|
"diastolic": 82,
|
||||||
|
"pulse": 68,
|
||||||
|
"measurementContext": {
|
||||||
|
"setting": "Home",
|
||||||
|
"activityCondition": "AtRest",
|
||||||
|
"restDurationMinutes": 5.5,
|
||||||
|
"bodyPosition": "Seated",
|
||||||
|
"measuredArm": "Left",
|
||||||
|
"deviceDetails": "Example upper-arm device",
|
||||||
|
"cuffDetails": "Example cuff",
|
||||||
|
"additionalCircumstances": "Recent stress"
|
||||||
|
},
|
||||||
|
"context": "Before breakfast",
|
||||||
|
"note": "Actual reading"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported `setting` values are `Home`, `Clinic`, `Other`, and `Unknown`;
|
||||||
|
`activityCondition` values are `AtRest`, `DuringActivity`, `AfterActivity`, and
|
||||||
|
`Unknown`. Category names are case-sensitive. Omitted/null categories, or an
|
||||||
|
omitted/null object, become `Unknown`; other omitted details stay null. Unsupported
|
||||||
|
categories and malformed fields return `400` validation details without saving.
|
||||||
|
Rest duration is optional, in minutes, and may be zero or any nonnegative decimal.
|
||||||
|
There is no minimum rest duration or posture requirement for accepting a reading.
|
||||||
|
The remaining optional details are narrative text, not technique certification.
|
||||||
|
Legacy context and notes are retained verbatim, including conflicts with categories;
|
||||||
|
no category is inferred from free text. Interpretation of conflicts belongs to
|
||||||
|
US-11. The structured object is included on observation reads and numeric-update
|
||||||
|
responses, including latest/history through their existing observation DTO.
|
||||||
|
|
||||||
|
Apply the `RecordedMeasurementContext` Observation migration before starting the
|
||||||
|
updated service. EF Core maps the owned value to columns in the same observation
|
||||||
|
table; no new table, service or dependency is introduced. Existing rows receive
|
||||||
|
unknown categories and null details without changing their measurements, timestamps
|
||||||
|
or text. Context filtering and context-only updates remain under US-07/US-08.
|
||||||
|
|
||||||
|
The Observation Service checks patient existence by calling the gateway's patient retrieval API over HTTP before saving. It has no reference to Patient/Profile implementation code and no access to that service's database. Missing patients return `404`; validation failures return `400`. Patient lookup failures return `502` or `504` and do not save an observation. Measurement timestamps without an offset represent UTC clock values and are stored as supplied, independently of the host time zone; timestamps with an offset are normalized to UTC. PostgreSQL uses the diagram's `timestamp` columns without a time-zone component.
|
||||||
|
|
||||||
`GET /api/patients/{patientId}/observations/latest` returns `200` with that patient's observation having the greatest measurement timestamp, regardless of recording order. It returns `404` when no observation is available. Equal measurement timestamps are resolved consistently by observation identifier; US-06 does not prescribe which tied observation to return. Selection happens in the Observation Service's own database through the documented controller/application-service/repository layers.
|
`GET /api/patients/{patientId}/observations/latest` returns `200` with that patient's observation having the greatest measurement timestamp, regardless of recording order. It returns `404` when no observation is available. Equal measurement timestamps are resolved consistently by observation identifier; US-06 does not prescribe which tied observation to return. Selection happens in the Observation Service's own database through the documented controller/application-service/repository layers.
|
||||||
|
|
||||||
@@ -138,7 +180,7 @@ The xUnit tests send HTTP requests to the gateway; the gateway reaches a real Ke
|
|||||||
|
|
||||||
US-02 retrieval scenarios are covered by the creation tests. US-03 tests cover persisted updates after restart, preservation of identity and date of birth, missing-patient rejection without insertion, and invalid-name rejection without changing the profile.
|
US-02 retrieval scenarios are covered by the creation tests. US-03 tests cover persisted updates after restart, preservation of identity and date of birth, missing-patient rejection without insertion, and invalid-name rejection without changing the profile.
|
||||||
|
|
||||||
US-04 tests use real HTTP between all three hosts and separate temporary patient and observation databases. They cover every recording acceptance scenario, retrieval after restart, optional fields, distinct identifiers, malformed/missing fields, missing observations, and patient-lookup failure without database writes. Both services' committed migrations are applied twice to verify idempotence. The Observation Service uses the same EF Core PostgreSQL dependencies as Patient/Profile for its independent persistence; no new library types are introduced.
|
US-04 tests use real HTTP between the hosts and separate temporary patient and observation databases. They cover every recording acceptance scenario, retrieval after restart, optional fields, distinct identifiers, malformed/missing fields, missing observations, and patient-lookup failure without database writes. Both services' committed migrations are applied twice to verify idempotence. Context tests also verify complete/partial/absent context, departures from guidance, validation without writes, authorised professional reads, restart persistence, numeric-update preservation, and upgrading historical observations without deriving categories from free text. The Observation Service uses the same EF Core PostgreSQL dependencies as Patient/Profile for its independent persistence; no new library types are introduced.
|
||||||
|
|
||||||
Dependencies: Npgsql's EF Core PostgreSQL provider supplies persistence; EF Core Relational is pinned to the same patch as EF Core Design to keep runtime/tooling versions aligned; EF Core Design supports migration maintenance. xUnit, its Visual Studio runner, Microsoft.NET.Test.Sdk, and ASP.NET Core MVC Testing are used only for automated tests. The gateway uses the platform's HttpClient and has no extra package dependency.
|
Dependencies: Npgsql's EF Core PostgreSQL provider supplies persistence; EF Core Relational is pinned to the same patch as EF Core Design to keep runtime/tooling versions aligned; EF Core Design supports migration maintenance. xUnit, its Visual Studio runner, Microsoft.NET.Test.Sdk, and ASP.NET Core MVC Testing are used only for automated tests. The gateway uses the platform's HttpClient and has no extra package dependency.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql;
|
||||||
|
using ObservationService.Persistence;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Observation.AcceptanceTests;
|
||||||
|
|
||||||
|
public sealed class MeasurementContextMigrationTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Upgrading_an_existing_observation_retains_values_and_text_without_inventing_context()
|
||||||
|
{
|
||||||
|
var admin = Environment.GetEnvironmentVariable("TEST_POSTGRES_CONNECTION")
|
||||||
|
?? throw new InvalidOperationException("TEST_POSTGRES_CONNECTION is required.");
|
||||||
|
var database = "us04_context_upgrade_" + Guid.NewGuid().ToString("N");
|
||||||
|
await using var connection = new NpgsqlConnection(admin);
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await using (var create = new NpgsqlCommand($"CREATE DATABASE {database}", connection))
|
||||||
|
await create.ExecuteNonQueryAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<ObservationDbContext>().UseNpgsql(
|
||||||
|
new NpgsqlConnectionStringBuilder(admin) { Database = database }.ConnectionString).Options;
|
||||||
|
await using var db = new ObservationDbContext(options);
|
||||||
|
await db.GetService<IMigrator>().MigrateAsync("20261001095222_InitialObservationSchema");
|
||||||
|
var observation = Guid.NewGuid();
|
||||||
|
var patient = Guid.NewGuid();
|
||||||
|
await db.Database.ExecuteSqlInterpolatedAsync($"""
|
||||||
|
INSERT INTO blood_pressure_observation
|
||||||
|
(observation_id, patient_id, measured_at, systolic, diastolic, pulse, context, note, created_at, updated_at)
|
||||||
|
VALUES ({observation}, {patient}, '2026-09-12 08:00:00', 128, 82, 68,
|
||||||
|
'Morning reading; resting?', 'Historical note', '2026-09-12 09:00:00', '2026-09-12 09:00:00')
|
||||||
|
""");
|
||||||
|
await db.Database.MigrateAsync();
|
||||||
|
await db.Database.MigrateAsync();
|
||||||
|
var saved = await db.Observations.AsNoTracking().SingleAsync();
|
||||||
|
Assert.Equal(observation, saved.ObservationId);
|
||||||
|
Assert.Equal(patient, saved.PatientId);
|
||||||
|
Assert.Equal(new DateTime(2026, 9, 12, 8, 0, 0), saved.MeasuredAt);
|
||||||
|
Assert.Equal(128, saved.Systolic);
|
||||||
|
Assert.Equal(82, saved.Diastolic);
|
||||||
|
Assert.Equal(68, saved.Pulse);
|
||||||
|
Assert.Equal("Morning reading; resting?", saved.Context);
|
||||||
|
Assert.Equal("Historical note", saved.Note);
|
||||||
|
Assert.Equal("Unknown", saved.MeasurementContext.Setting);
|
||||||
|
Assert.Equal("Unknown", saved.MeasurementContext.ActivityCondition);
|
||||||
|
Assert.Null(saved.MeasurementContext.RestDurationMinutes);
|
||||||
|
Assert.Null(saved.MeasurementContext.BodyPosition);
|
||||||
|
Assert.Null(saved.MeasurementContext.MeasuredArm);
|
||||||
|
Assert.Null(saved.MeasurementContext.DeviceDetails);
|
||||||
|
Assert.Null(saved.MeasurementContext.CuffDetails);
|
||||||
|
Assert.Null(saved.MeasurementContext.AdditionalCircumstances);
|
||||||
|
Assert.Equal(new DateTime(2026, 9, 12, 9, 0, 0), saved.CreatedAt);
|
||||||
|
Assert.Equal(saved.CreatedAt, saved.UpdatedAt);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await using var drop = new NpgsqlCommand($"DROP DATABASE {database} WITH (FORCE)", connection);
|
||||||
|
await drop.ExecuteNonQueryAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using HealthApp.TestSupport;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Observation.AcceptanceTests;
|
||||||
|
|
||||||
|
public sealed class RecordMeasurementContextTests(ObservationApiFixture fixture) : IClassFixture<ObservationApiFixture>
|
||||||
|
{
|
||||||
|
private sealed record Profile(Guid PatientId);
|
||||||
|
private sealed record Context(string Setting, string ActivityCondition, decimal? RestDurationMinutes,
|
||||||
|
string? BodyPosition, string? MeasuredArm, string? DeviceDetails, string? CuffDetails, string? AdditionalCircumstances);
|
||||||
|
private sealed record Observation(Guid ObservationId, Guid PatientId, DateTime MeasuredAt,
|
||||||
|
int Systolic, int Diastolic, int Pulse, string? Context, string? Note, Context MeasurementContext);
|
||||||
|
|
||||||
|
private async Task<Guid> Patient()
|
||||||
|
{
|
||||||
|
using var response = await fixture.Client.PostAsJsonAsync("/api/patients", new { name = "Context patient", dateOfBirth = "1980-01-01" });
|
||||||
|
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||||
|
return (await response.Content.ReadFromJsonAsync<Profile>())!.PatientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task<HttpResponseMessage> Record(Guid patientId, object? measurementContext, string? context = null, string? note = null) =>
|
||||||
|
fixture.Client.PostAsJsonAsync($"/api/patients/{patientId}/observations", new
|
||||||
|
{
|
||||||
|
measuredAt = "2026-09-12T08:00:00", systolic = 128, diastolic = 82, pulse = 68,
|
||||||
|
measurementContext, context, note
|
||||||
|
});
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Complete_context_is_saved_with_the_correct_values_and_retrievable_after_restart()
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
var expected = new Context("Home", "AtRest", 5.5m, "Seated", "Left", "Example upper-arm device",
|
||||||
|
"Example cuff", "Recent stress");
|
||||||
|
using var response = await Record(patient, expected, "Before breakfast", "Actual reading");
|
||||||
|
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||||
|
var saved = (await response.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal(expected, saved.MeasurementContext);
|
||||||
|
Assert.Equal(patient, saved.PatientId);
|
||||||
|
Assert.Equal(new DateTime(2026, 9, 12, 8, 0, 0), saved.MeasuredAt);
|
||||||
|
Assert.Equal(128, saved.Systolic);
|
||||||
|
Assert.Equal(82, saved.Diastolic);
|
||||||
|
Assert.Equal(68, saved.Pulse);
|
||||||
|
Assert.Equal("Before breakfast", saved.Context);
|
||||||
|
Assert.Equal("Actual reading", saved.Note);
|
||||||
|
await fixture.RestartHostsAsync();
|
||||||
|
Assert.Equal(saved, await fixture.Client.GetFromJsonAsync<Observation>(response.Headers.Location));
|
||||||
|
var latest = await fixture.Client.GetFromJsonAsync<Observation>($"/api/patients/{patient}/observations/latest");
|
||||||
|
Assert.Equal(saved, latest);
|
||||||
|
var history = await fixture.Client.GetFromJsonAsync<Observation[]>($"/api/patients/{patient}/observations?from=2026-09-11&to=2026-09-13");
|
||||||
|
Assert.Equal(saved, Assert.Single(history!));
|
||||||
|
using var corrected = await fixture.Client.PutAsJsonAsync($"/api/observations/{saved.ObservationId}",
|
||||||
|
new { systolic = 130, diastolic = 84, pulse = 70 });
|
||||||
|
Assert.Equal(HttpStatusCode.OK, corrected.StatusCode);
|
||||||
|
Assert.Equal(expected, (await corrected.Content.ReadFromJsonAsync<Observation>())!.MeasurementContext);
|
||||||
|
await using var db = fixture.CreateObservationDbContext();
|
||||||
|
var persisted = await db.Observations.SingleAsync(o => o.ObservationId == saved.ObservationId);
|
||||||
|
Assert.Equal(5.5m, persisted.MeasurementContext.RestDurationMinutes);
|
||||||
|
Assert.Equal("Home", persisted.MeasurementContext.Setting);
|
||||||
|
Assert.Equal("Example cuff", persisted.MeasurementContext.CuffDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Home", "AtRest")]
|
||||||
|
[InlineData("Home", "DuringActivity")]
|
||||||
|
[InlineData("Clinic", "AfterActivity")]
|
||||||
|
[InlineData("Other", "Unknown")]
|
||||||
|
[InlineData("Unknown", "AtRest")]
|
||||||
|
[InlineData("Unknown", "Unknown")]
|
||||||
|
public async Task Setting_and_activity_are_independent_and_departures_from_guidance_are_valid(string setting, string activity)
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
using var response = await Record(patient, new { setting, activityCondition = activity,
|
||||||
|
restDurationMinutes = 0m, bodyPosition = "Standing", additionalCircumstances = "Walking immediately beforehand" });
|
||||||
|
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||||
|
var saved = (await response.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal(setting, saved.MeasurementContext.Setting);
|
||||||
|
Assert.Equal(activity, saved.MeasurementContext.ActivityCondition);
|
||||||
|
Assert.Equal(0m, saved.MeasurementContext.RestDurationMinutes);
|
||||||
|
Assert.Equal("Standing", saved.MeasurementContext.BodyPosition);
|
||||||
|
Assert.Equal("Walking immediately beforehand", saved.MeasurementContext.AdditionalCircumstances);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Partial_and_absent_context_remain_unknown_without_reinterpreting_legacy_text()
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
using var partial = await Record(patient, new { setting = "Clinic" });
|
||||||
|
var first = (await partial.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal(HttpStatusCode.Created, partial.StatusCode);
|
||||||
|
Assert.Equal("Clinic", first.MeasurementContext.Setting);
|
||||||
|
Assert.Equal("Unknown", first.MeasurementContext.ActivityCondition);
|
||||||
|
Assert.Null(first.MeasurementContext.RestDurationMinutes);
|
||||||
|
Assert.Null(first.MeasurementContext.BodyPosition);
|
||||||
|
using var absent = await Record(patient, null, "Morning reading; resting?", "Keep original text");
|
||||||
|
var second = (await absent.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal(HttpStatusCode.Created, absent.StatusCode);
|
||||||
|
Assert.Equal("Unknown", second.MeasurementContext.Setting);
|
||||||
|
Assert.Equal("Unknown", second.MeasurementContext.ActivityCondition);
|
||||||
|
Assert.Equal("Morning reading; resting?", second.Context);
|
||||||
|
Assert.Equal("Keep original text", second.Note);
|
||||||
|
Assert.Equal(second, await fixture.Client.GetFromJsonAsync<Observation>(absent.Headers.Location));
|
||||||
|
using var explicitNulls = await Record(patient, new { setting = (string?)null, activityCondition = (string?)null });
|
||||||
|
Assert.Equal(HttpStatusCode.Created, explicitNulls.StatusCode);
|
||||||
|
var third = (await explicitNulls.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal("Unknown", third.MeasurementContext.Setting);
|
||||||
|
Assert.Equal("Unknown", third.MeasurementContext.ActivityCondition);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Conflicting_categories_and_narrative_are_preserved_without_relabelling()
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
using var response = await Record(patient, new { setting = "Home", activityCondition = "AtRest",
|
||||||
|
additionalCircumstances = "During exercise" }, "During exercise", "Recorded as supplied");
|
||||||
|
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
|
||||||
|
var saved = (await response.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
Assert.Equal("AtRest", saved.MeasurementContext.ActivityCondition);
|
||||||
|
Assert.Equal("During exercise", saved.MeasurementContext.AdditionalCircumstances);
|
||||||
|
Assert.Equal("During exercise", saved.Context);
|
||||||
|
Assert.Equal(saved, await fixture.Client.GetFromJsonAsync<Observation>(response.Headers.Location));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("{\"setting\":\"Unsupported\"}")]
|
||||||
|
[InlineData("{\"activityCondition\":\"Unsupported\"}")]
|
||||||
|
[InlineData("{\"setting\":42}")]
|
||||||
|
[InlineData("{\"activityCondition\":true}")]
|
||||||
|
[InlineData("{\"restDurationMinutes\":-1}")]
|
||||||
|
public async Task Invalid_context_is_rejected_with_validation_details_without_saving(string contextJson)
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
await using var db = fixture.CreateObservationDbContext();
|
||||||
|
var before = await db.Observations.CountAsync();
|
||||||
|
var json = "{\"measuredAt\":\"2026-09-12T08:00:00\",\"systolic\":128,\"diastolic\":82,\"pulse\":68,\"measurementContext\":" + contextJson + "}";
|
||||||
|
using var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
using var response = await fixture.Client.PostAsync($"/api/patients/{patient}/observations", content);
|
||||||
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
|
using var problem = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
Assert.True(problem.RootElement.TryGetProperty("errors", out _));
|
||||||
|
Assert.Equal(before, await db.Observations.CountAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Context_is_protected_against_other_patient_reads_and_submissions_and_professional_writes()
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
var otherPatient = await Patient();
|
||||||
|
using var recorded = await Record(patient, new { setting = "Home", activityCondition = "AtRest" });
|
||||||
|
Assert.Equal(HttpStatusCode.Created, recorded.StatusCode);
|
||||||
|
var observation = (await recorded.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
var otherToken = await AuthenticatedTestClient.LoginAsync(fixture.RawClient, fixture.Authentication.PatientAccounts[otherPatient]);
|
||||||
|
await using var db = fixture.CreateObservationDbContext();
|
||||||
|
var count = await db.Observations.CountAsync();
|
||||||
|
using var read = new HttpRequestMessage(HttpMethod.Get, $"/api/observations/{observation.ObservationId}");
|
||||||
|
read.Headers.Authorization = new("Bearer", otherToken);
|
||||||
|
using var rejectedRead = await fixture.RawClient.SendAsync(read);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, rejectedRead.StatusCode);
|
||||||
|
Assert.Empty(await rejectedRead.Content.ReadAsStringAsync());
|
||||||
|
foreach (var token in new[] { otherToken, await AuthenticatedTestClient.LoginAsync(fixture.RawClient, "professional") })
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Post, $"/api/patients/{patient}/observations")
|
||||||
|
{
|
||||||
|
Content = JsonContent.Create(new { measuredAt = "2026-09-12T08:00:00", systolic = 128, diastolic = 82,
|
||||||
|
pulse = 68, measurementContext = new { setting = "Clinic" } })
|
||||||
|
};
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
using var response = await fixture.RawClient.SendAsync(request);
|
||||||
|
Assert.Equal(token == otherToken ? HttpStatusCode.NotFound : HttpStatusCode.Forbidden, response.StatusCode);
|
||||||
|
}
|
||||||
|
Assert.Equal(count, await db.Observations.CountAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Assigned_professional_can_retrieve_saved_context()
|
||||||
|
{
|
||||||
|
var patient = await Patient();
|
||||||
|
using var recorded = await Record(patient, new { setting = "Clinic", activityCondition = "AtRest", deviceDetails = "Clinic device" });
|
||||||
|
Assert.Equal(HttpStatusCode.Created, recorded.StatusCode);
|
||||||
|
var saved = (await recorded.Content.ReadFromJsonAsync<Observation>())!;
|
||||||
|
fixture.AdditionalGatewayConfiguration["Access:ProfessionalAssignments:professional:0"] = patient.ToString();
|
||||||
|
await fixture.RestartHostsAsync();
|
||||||
|
var token = await AuthenticatedTestClient.LoginAsync(fixture.RawClient, "professional");
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, $"/api/observations/{saved.ObservationId}");
|
||||||
|
request.Headers.Authorization = new("Bearer", token);
|
||||||
|
using var response = await fixture.RawClient.SendAsync(request);
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
Assert.Equal(saved, await response.Content.ReadFromJsonAsync<Observation>());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user