Skip to content

Commit 973e685

Browse files
authored
LNK-4316: Remove Namespace and Project as $type data from QueryPlan API (#1237)
* This update removes the requirement to send API model namespace and project names as $type data in the API call. A Caller should not have to know our internal namespace structure when calling our API's. Futhermore, changing namespaces will require the API users to be aware of those name space changes, or else the API will not "break", which happened as a result of the POI shuffling of models into new directories. * checkin * revet appsettings.json * add DBContext conversion * checkin * checkin * checkin * Add a bunch of tests
1 parent 5527048 commit 973e685

24 files changed

Lines changed: 1429 additions & 521 deletions

File tree

DotNet/DataAcquisition.Domain/Application/Managers/QueryPlanManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public async Task<QueryPlanModel> AddAsync(CreateQueryPlanModel model, Cancellat
3636
throw new ArgumentNullException(nameof(model), "CreateQueryPlanModel cannot be null.");
3737
}
3838

39-
// Validate query order
39+
//// Validate query order
4040
ValidateQueryOrder(model.InitialQueries, "InitialQueries");
4141
ValidateQueryOrder(model.SupplementalQueries, "SupplementalQueries");
4242

43+
var date = DateTime.UtcNow;
44+
4345
var entity = new QueryPlan
4446
{
4547
PlanName = model.PlanName,
@@ -49,8 +51,8 @@ public async Task<QueryPlanModel> AddAsync(CreateQueryPlanModel model, Cancellat
4951
InitialQueries = model.InitialQueries,
5052
SupplementalQueries = model.SupplementalQueries,
5153
Type = model.Type,
52-
CreateDate = DateTime.UtcNow,
53-
ModifyDate = DateTime.UtcNow
54+
CreateDate = date,
55+
ModifyDate = date
5456
};
5557

5658
entity = await _database.QueryPlanRepository.AddAsync(entity);

DotNet/DataAcquisition.Domain/Application/Models/Http/QueryPlanBaseModel.cs renamed to DotNet/DataAcquisition.Domain/Application/Models/Http/QueryPlanApiModel.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text.Json.Serialization;
77

88
namespace LantanaGroup.Link.DataAcquisition.Domain.Application.Models.Http;
9-
public class QueryPlanBaseModel
9+
public class QueryPlanApiModel
1010
{
1111
[DataMember]
1212
public string? PlanName { get; set; }
@@ -18,12 +18,31 @@ public class QueryPlanBaseModel
1818
public string? EHRDescription { get; set; }
1919
[DataMember]
2020
public string? LookBack { get; set; }
21+
2122
[DataMember, Required, MinDictionaryCount(1)]
2223
public Dictionary<string, IQueryConfig> InitialQueries { get; set; }
24+
2325
[DataMember, Required, MinDictionaryCount(1)]
2426
public Dictionary<string, IQueryConfig> SupplementalQueries { get; set; }
27+
2528
[IgnoreDataMember, JsonIgnore]
2629
public DateTime? CreateDate { get; set; }
2730
[IgnoreDataMember, JsonIgnore]
2831
public DateTime? ModifyDate { get; set; }
32+
33+
public bool Validate()
34+
{
35+
if (string.IsNullOrWhiteSpace(this.PlanName))
36+
throw new ArgumentNullException(nameof(this.PlanName), "PlanName cannot be null or empty.");
37+
if (this.Type is null)
38+
throw new ArgumentNullException(nameof(this.Type), "Type is required.");
39+
if (string.IsNullOrWhiteSpace(this.FacilityId))
40+
throw new ArgumentNullException(nameof(this.FacilityId), "FacilityId is required.");
41+
if (this.InitialQueries is null || !this.InitialQueries.Any())
42+
throw new ArgumentNullException(nameof(this.InitialQueries), "InitialQueries is required.");
43+
if (this.SupplementalQueries is null || !this.SupplementalQueries.Any())
44+
throw new ArgumentNullException(nameof(this.SupplementalQueries), "SupplementalQueries is required.");
45+
46+
return true;
47+
}
2948
}

DotNet/DataAcquisition.Domain/Application/Models/Http/QueryPlanPostModel.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

DotNet/DataAcquisition.Domain/Application/Models/Http/QueryPlanPutModel.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

DotNet/DataAcquisition.Domain/Application/Queries/QueryPlanQueries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<PagedConfigModel<QueryPlanModel>> SearchAsync(SearchQueryPlanM
5656
{
5757
ArgumentNullException.ThrowIfNull(model);
5858

59-
var query = _dbContext.QueryPlan.AsNoTracking().AsQueryable();
59+
var query = _dbContext.QueryPlans.AsNoTracking().AsQueryable();
6060

6161
if (!string.IsNullOrEmpty(model.FacilityId))
6262
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Interfaces;
2+
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Models.QueryConfig.Parameter;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace LantanaGroup.Link.DataAcquisition.Domain.Application.Serializers;
7+
8+
public class ParameterConverter : JsonConverter<IParameter>
9+
{
10+
public override IParameter Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
11+
{
12+
using (JsonDocument doc = JsonDocument.ParseValue(ref reader))
13+
{
14+
if (!doc.RootElement.TryGetProperty("ParameterType", out JsonElement typeElement))
15+
{
16+
if (!doc.RootElement.TryGetProperty("parameterType", out typeElement))
17+
{
18+
throw new JsonException("Missing ParameterType property.");
19+
}
20+
}
21+
var configType = typeElement.GetString();
22+
return configType switch
23+
{
24+
"Literal" => JsonSerializer.Deserialize<LiteralParameter>(doc.RootElement.GetRawText(), options),
25+
"ResourceIds" => JsonSerializer.Deserialize<ResourceIdsParameter>(doc.RootElement.GetRawText(), options),
26+
"Variable" => JsonSerializer.Deserialize<VariableParameter>(doc.RootElement.GetRawText(), options),
27+
_ => throw new JsonException($"Unknown ParameterType: {configType}")
28+
};
29+
}
30+
}
31+
public override void Write(Utf8JsonWriter writer, IParameter value, JsonSerializerOptions options)
32+
{
33+
JsonSerializer.Serialize(writer, value, value.GetType(), options);
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Interfaces;
2+
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Models.QueryConfig;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace LantanaGroup.Link.DataAcquisition.Domain.Application.Serializers;
7+
8+
public class QueryConfigConverter : JsonConverter<IQueryConfig>
9+
{
10+
public override IQueryConfig Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
11+
{
12+
using (JsonDocument doc = JsonDocument.ParseValue(ref reader))
13+
{
14+
if (!doc.RootElement.TryGetProperty("QueryConfigType", out JsonElement typeElement))
15+
{
16+
if (!doc.RootElement.TryGetProperty("queryConfigType", out typeElement))
17+
{
18+
throw new JsonException("Missing QueryConfigType property.");
19+
}
20+
}
21+
var configType = typeElement.GetString();
22+
return configType switch
23+
{
24+
"Parameter" => JsonSerializer.Deserialize<ParameterQueryConfig>(doc.RootElement.GetRawText(), options),
25+
"Reference" => JsonSerializer.Deserialize<ReferenceQueryConfig>(doc.RootElement.GetRawText(), options),
26+
_ => throw new JsonException($"Unknown QueryConfigType: {configType}")
27+
};
28+
}
29+
}
30+
public override void Write(Utf8JsonWriter writer, IQueryConfig value, JsonSerializerOptions options)
31+
{
32+
JsonSerializer.Serialize(writer, value, value.GetType(), options);
33+
}
34+
}

DotNet/DataAcquisition.Domain/Application/Serializers/QueryPlanConverter.cs

Lines changed: 0 additions & 115 deletions
This file was deleted.

DotNet/DataAcquisition.Domain/Infrastructure/Context/DataAcquisitionDbContext.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using AppAny.Quartz.EntityFrameworkCore.Migrations;
22
using AppAny.Quartz.EntityFrameworkCore.Migrations.SqlServer;
3+
using LantanaGroup.Link.DataAcquisition.Domain.Application.Serializers;
34
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Entities;
45
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Interfaces;
56
using LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Models;
@@ -10,6 +11,7 @@
1011
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
1112
using Microsoft.Extensions.Configuration;
1213
using System.Text.Json;
14+
using System.Text.Json.Serialization;
1315
using RequestStatus = LantanaGroup.Link.DataAcquisition.Domain.Infrastructure.Models.Enums.RequestStatus;
1416
using ScheduledReport = LantanaGroup.Link.Shared.Application.Models.ScheduledReport;
1517

@@ -23,7 +25,7 @@ public DataAcquisitionDbContext(DbContextOptions<DataAcquisitionDbContext> optio
2325

2426
public DbSet<FhirQueryConfiguration> FhirQueryConfigurations { get; set; }
2527
public DbSet<FhirListConfiguration> FhirListConfigurations { get; set; }
26-
public DbSet<QueryPlan> QueryPlan { get; set; }
28+
public DbSet<QueryPlan> QueryPlans { get; set; }
2729
public DbSet<ReferenceResources> ReferenceResources { get; set; }
2830
public DbSet<FhirQuery> FhirQueries { get; set; }
2931
public virtual DbSet<FhirQueryResourceType> FhirQueryResourceTypes { get; set; }
@@ -37,15 +39,20 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3739
{
3840
entity.Property(e => e.Id).ValueGeneratedOnAdd();
3941

42+
var jsonOptions = new JsonSerializerOptions();
43+
jsonOptions.Converters.Add(new QueryConfigConverter());
44+
jsonOptions.Converters.Add(new ParameterConverter());
45+
jsonOptions.Converters.Add(new JsonStringEnumConverter());
46+
4047
entity.Property(b => b.InitialQueries)
4148
.HasConversion(
42-
v => JsonSerializer.Serialize(v, new JsonSerializerOptions()),
43-
v => JsonSerializer.Deserialize<Dictionary<string, IQueryConfig>>(v, new JsonSerializerOptions()));
49+
v => JsonSerializer.Serialize(v, jsonOptions),
50+
v => JsonSerializer.Deserialize<Dictionary<string, IQueryConfig>>(v, jsonOptions));
4451

4552
entity.Property(b => b.SupplementalQueries)
4653
.HasConversion(
47-
v => JsonSerializer.Serialize(v, new JsonSerializerOptions()),
48-
v => JsonSerializer.Deserialize<Dictionary<string, IQueryConfig>>(v, new JsonSerializerOptions()));
54+
v => JsonSerializer.Serialize(v, jsonOptions),
55+
v => JsonSerializer.Deserialize<Dictionary<string, IQueryConfig>>(v, jsonOptions));
4956
});
5057

5158
//-------------------FhirQueryConfiguration-------------------

0 commit comments

Comments
 (0)