Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 47f62dc

Browse files
refactor: Replaced foreach loop with linq expression and using invariant culture for DateTime Parsing
1 parent 8b319ef commit 47f62dc

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed
Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using ServiceLayer.Data;
23
using ServiceLayer.Data.Models;
34
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents.Models;
@@ -16,44 +17,37 @@ public async Task WriteStagedData(ParsedFile parsedFile, MeshFile meshFile)
1617

1718
private static List<NbssAppointmentEvent> MapFileDataRecordsToNbssAppointmentEvents(ParsedFile parsedFile, string fileId)
1819
{
19-
var events = new List<NbssAppointmentEvent>();
20-
21-
foreach (var record in parsedFile.DataRecords)
20+
return [.. parsedFile.DataRecords.Select(record => new NbssAppointmentEvent
2221
{
23-
events.Add(new NbssAppointmentEvent
24-
{
25-
MeshFileId = fileId,
26-
BSO = record.Fields["BSO"],
27-
ExtractId = parsedFile.FileHeader!.ExtractId!,
28-
Sequence = record.Fields["Sequence"],
29-
Action = record.Fields["Action"],
30-
ClinicCode = record.Fields["Clinic Code"],
31-
HoldingClinic = record.Fields["Holding Clinic"],
32-
Status = record.Fields["Status"],
33-
AttendedNotScreened = record.Fields["Attended Not Scr"],
34-
AppointmenId = record.Fields["Appointment ID"],
35-
NhsNumber = record.Fields["NHS Num"],
36-
EpisodeType = record.Fields["Episode Type"],
37-
EpisodeStart = DateOnly.ParseExact(record.Fields["Episode Start"], "yyyyMMdd"),
38-
BatchId = record.Fields["Batch ID"],
39-
AppointmentType = record.Fields["Screen or Asses"],
40-
ScreeningAppointmentNumber = byte.Parse(record.Fields["Screen Appt num"]),
41-
BookedBy = record.Fields["Booked By"],
42-
CancelledBy = record.Fields["Cancelled By"],
43-
AppointmentDateTime = DateTime.ParseExact(record.Fields["Appt Date"] + record.Fields["Appt Time"], "yyyyMMddHHmm", null),
44-
Location = record.Fields["Location"],
45-
ClinicName = record.Fields["Clinic Name"],
46-
ClinicNameOnLetters = record.Fields["Clinic Name (Let)"],
47-
ClinicAddressLine1 = record.Fields["Clinic Address 1"],
48-
ClinicAddressLine2 = record.Fields["Clinic Address 2"],
49-
ClinicAddressLine3 = record.Fields["Clinic Address 3"],
50-
ClinicAddressLine4 = record.Fields["Clinic Address 4"],
51-
ClinicAddressLine5 = record.Fields["Clinic Address 5"],
52-
ClinicPostcode = record.Fields["Postcode"],
53-
ActionTimestamp = DateTime.ParseExact(record.Fields["Action Timestamp"], "yyyyMMdd-HHmmss", null)
54-
});
55-
}
56-
57-
return events;
22+
MeshFileId = fileId,
23+
BSO = record.Fields["BSO"],
24+
ExtractId = parsedFile.FileHeader!.ExtractId!,
25+
Sequence = record.Fields["Sequence"],
26+
Action = record.Fields["Action"],
27+
ClinicCode = record.Fields["Clinic Code"],
28+
HoldingClinic = record.Fields["Holding Clinic"],
29+
Status = record.Fields["Status"],
30+
AttendedNotScreened = record.Fields["Attended Not Scr"],
31+
AppointmenId = record.Fields["Appointment ID"],
32+
NhsNumber = record.Fields["NHS Num"],
33+
EpisodeType = record.Fields["Episode Type"],
34+
EpisodeStart = DateOnly.ParseExact(record.Fields["Episode Start"], "yyyyMMdd", CultureInfo.InvariantCulture),
35+
BatchId = record.Fields["Batch ID"],
36+
AppointmentType = record.Fields["Screen or Asses"],
37+
ScreeningAppointmentNumber = byte.Parse(record.Fields["Screen Appt num"]),
38+
BookedBy = record.Fields["Booked By"],
39+
CancelledBy = record.Fields["Cancelled By"],
40+
AppointmentDateTime = DateTime.ParseExact(record.Fields["Appt Date"] + record.Fields["Appt Time"], "yyyyMMddHHmm", CultureInfo.InvariantCulture),
41+
Location = record.Fields["Location"],
42+
ClinicName = record.Fields["Clinic Name"],
43+
ClinicNameOnLetters = record.Fields["Clinic Name (Let)"],
44+
ClinicAddressLine1 = record.Fields["Clinic Address 1"],
45+
ClinicAddressLine2 = record.Fields["Clinic Address 2"],
46+
ClinicAddressLine3 = record.Fields["Clinic Address 3"],
47+
ClinicAddressLine4 = record.Fields["Clinic Address 4"],
48+
ClinicAddressLine5 = record.Fields["Clinic Address 5"],
49+
ClinicPostcode = record.Fields["Postcode"],
50+
ActionTimestamp = DateTime.ParseExact(record.Fields["Action Timestamp"], "yyyyMMdd-HHmmss", CultureInfo.InvariantCulture)
51+
})];
5852
}
5953
}

0 commit comments

Comments
 (0)