Skip to content

Commit 827e12e

Browse files
authored
Merge branch 'dev' into nvm/LNK-4430_Handle429QueryCase
2 parents 90e4fed + 6c1cacb commit 827e12e

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

DotNet/DataAcquisition.Domain/Application/Services/PatientDataService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public async Task CreateLogEntries(GetPatientDataRequest request, CancellationTo
208208

209209
if (queryPlan != null)
210210
{
211-
var initialQueries = queryPlan.InitialQueries.OrderBy(x => x.Key);
212-
var supplementalQueries = queryPlan.SupplementalQueries.OrderBy(x => x.Key);
211+
var initialQueries = queryPlan.InitialQueries.OrderBy(x => int.TryParse(x.Key, out int num) ? num : int.MaxValue);
212+
var supplementalQueries = queryPlan.SupplementalQueries.OrderBy(x => int.TryParse(x.Key, out int num) ? num : int.MaxValue);
213213

214214
var referenceStrTypes = queryPlan.InitialQueries.Values.OfType<ReferenceQueryConfig>().Select(x => x.ResourceType).Distinct().ToList();
215215
referenceStrTypes.AddRange(queryPlan.SupplementalQueries.Values.OfType<ReferenceQueryConfig>().Select(x => x.ResourceType).Distinct().ToList());

DotNet/ServiceTests/UnitTests/DataAcquisition/QueryPlanConverterTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,50 @@ public void Deserialize_NewFullInitialQueriesDictionary_ShouldSucceed()
259259
Assert.IsType<ParameterQueryConfig>(dict["0"]);
260260
Assert.IsType<ReferenceQueryConfig>(dict["1"]);
261261
}
262+
263+
[Fact]
264+
public void OrderBy_DictionaryWithNumericStringKeys_ShouldSortNumerically()
265+
{
266+
var dict = new Dictionary<string, IQueryConfig>
267+
{
268+
["2"] = new ParameterQueryConfig { ResourceType = "Patient", Parameters = new List<IParameter>() },
269+
["10"] = new ReferenceQueryConfig { ResourceType = "Location", OperationType = OperationType.Search, Paged = 100 },
270+
["1"] = new ParameterQueryConfig { ResourceType = "Encounter", Parameters = new List<IParameter>() },
271+
["20"] = new ReferenceQueryConfig { ResourceType = "Organization", OperationType = OperationType.Search, Paged = 50 }
272+
};
273+
274+
var sorted = dict.OrderBy(x => int.Parse(x.Key)).ToList();
275+
276+
Assert.Equal("1", sorted[0].Key);
277+
Assert.Equal("2", sorted[1].Key);
278+
Assert.Equal("10", sorted[2].Key);
279+
Assert.Equal("20", sorted[3].Key);
280+
}
281+
282+
[Fact]
283+
public void OrderBy_DictionaryWithNumericStringKeys_AlphabeticSortingIsIncorrect()
284+
{
285+
var dict = new Dictionary<string, IQueryConfig>
286+
{
287+
["2"] = new ParameterQueryConfig { ResourceType = "Patient", Parameters = new List<IParameter>() },
288+
["10"] = new ReferenceQueryConfig { ResourceType = "Location", OperationType = OperationType.Search, Paged = 100 },
289+
["1"] = new ParameterQueryConfig { ResourceType = "Encounter", Parameters = new List<IParameter>() }
290+
};
291+
292+
// Alphabetic sort (incorrect for numeric keys)
293+
var alphabeticSort = dict.OrderBy(x => x.Key).ToList();
294+
295+
// This would give us "1", "10", "2" - wrong order
296+
Assert.Equal("1", alphabeticSort[0].Key);
297+
Assert.Equal("10", alphabeticSort[1].Key);
298+
Assert.Equal("2", alphabeticSort[2].Key);
299+
300+
// Numeric sort (correct)
301+
var numericSort = dict.OrderBy(x => int.Parse(x.Key)).ToList();
302+
303+
// This gives us "1", "2", "10" - correct order
304+
Assert.Equal("1", numericSort[0].Key);
305+
Assert.Equal("2", numericSort[1].Key);
306+
Assert.Equal("10", numericSort[2].Key);
307+
}
262308
}

0 commit comments

Comments
 (0)