Skip to content

Commit 2fa0f10

Browse files
fix: fxing date formatting (#1512)
* fix: fxing date formatting * fix: now maps all the dates * fix: fixing unit tests * fix: removing unwanted code * fix: removing unused usings
1 parent a30260d commit 2fa0f10

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace NHS.CohortManager.DemographicServices;
55
using System.Text.Json;
66
using Common;
77
using Common.Interfaces;
8-
using DataServices.Client;
98
using Microsoft.Azure.Functions.Worker;
109
using Microsoft.Azure.Functions.Worker.Http;
1110
using Microsoft.Extensions.Logging;

application/CohortManager/src/Functions/Shared/Common/FhirPatientDemographicMapper.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Common;
1010
using Model.Enums;
1111
using System;
1212
using System.Linq;
13+
using NHS.CohortManager.Shared.Utilities;
1314

1415
public class FhirPatientDemographicMapper : IFhirPatientDemographicMapper
1516
{
@@ -120,7 +121,7 @@ public PdsDemographic MapPatientToPDSDemographic(Patient patient)
120121
demographic.ParticipantId = null; // We do not know the Participant ID from PDS
121122
demographic.RecordUpdateDateTime = null; // We do not know the RecordUpdateDateTime from PDS
122123
demographic.RecordInsertDateTime = null; // We do not know the RecordInsertDateTime from PDS
123-
demographic.DateOfBirth = patient.BirthDate;
124+
demographic.DateOfBirth = FormatDates(patient.BirthDate);
124125

125126
// CurrentPosting & CurrentPostingEffectiveFromDate
126127
// these are not set as not available in PDS
@@ -150,7 +151,7 @@ private static void MapPrimaryCareProvider(Patient patient, Demographic demograp
150151
demographic.PrimaryCareProvider = gp.Identifier.Value;
151152

152153
if (gp.Identifier.Period?.Start != null)
153-
demographic.PrimaryCareProviderEffectiveFromDate = gp.Identifier.Period.Start.ToString();
154+
demographic.PrimaryCareProviderEffectiveFromDate = FormatDates(gp.Identifier.Period.Start);
154155
}
155156

156157
private static void MapNames(Patient patient, Demographic demographic)
@@ -246,7 +247,7 @@ private static void MapAddressComponents(Address address, Demographic demographi
246247
// Map effective date
247248
if (address.Period?.Start != null)
248249
{
249-
demographic.UsualAddressEffectiveFromDate = address.Period.Start.ToString();
250+
demographic.UsualAddressEffectiveFromDate = FormatDates(address.Period.Start);
250251
}
251252
}
252253

@@ -358,7 +359,7 @@ private static void MapContactPoint(
358359

359360
if (contactPoint.Period?.Start != null)
360361
{
361-
setDateAction(contactPoint.Period.Start.ToString());
362+
setDateAction(FormatDates(contactPoint.Period.Start));
362363
}
363364
}
364365

@@ -451,4 +452,11 @@ private static void MapSecurityMetadata(Patient patient, PdsDemographic demograp
451452

452453
demographic.ConfidentialityCode = confidentialityCoding.Code;
453454
}
455+
456+
private static string FormatDates(string dateToConvert)
457+
{
458+
var parsedDateTime = MappingUtilities.ParseDates(dateToConvert);
459+
return parsedDateTime?.ToString("yyyyMMdd")!;
460+
}
461+
454462
}

tests/UnitTests/SharedTests/FhirPatientDemographicMapperTests/FhirPatientDemographicMapperTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public void FhirParser_ValidJson_ReturnsDemographic()
9090
ParticipantId = null,
9191
RecordUpdateDateTime = null,
9292
RecordInsertDateTime = null,
93-
DateOfBirth = "2010-10-22",
93+
DateOfBirth = "20101022",
9494

9595
// Primary Care Provider
9696
PrimaryCareProvider = "Y12345",
97-
PrimaryCareProviderEffectiveFromDate = "2020-01-01",
97+
PrimaryCareProviderEffectiveFromDate = "20200101",
9898

9999
// Name Information
100100
NamePrefix = "Mrs",
@@ -114,19 +114,19 @@ public void FhirParser_ValidJson_ReturnsDemographic()
114114
AddressLine5 = "West Yorkshire",
115115
Postcode = "LS1 6AE",
116116
PafKey = "12345678",
117-
UsualAddressEffectiveFromDate = "2020-01-01",
117+
UsualAddressEffectiveFromDate = "20200101",
118118

119119
// Death Information
120120
DateOfDeath = "2010-10-22T00:00:00+00:00",
121121
DeathStatus = Status.Formal, // "Formal - death notice received from Registrar of Deaths"
122122

123123
// Contact Information
124124
TelephoneNumber = "01632960587", // Home phone
125-
TelephoneNumberEffectiveFromDate = "2020-01-01",
125+
TelephoneNumberEffectiveFromDate = "20200101",
126126
MobileNumber = null, // No mobile phone in the sample
127127
MobileNumberEffectiveFromDate = null,
128128
EmailAddress = "jane.smith@example.com",
129-
EmailAddressEffectiveFromDate = "2019-01-01",
129+
EmailAddressEffectiveFromDate = "20190101",
130130

131131
// Language Preferences
132132
PreferredLanguage = "fr",
@@ -215,7 +215,7 @@ public void FhirParser_SensitivePatient_MapsCorrectly()
215215

216216
// Basic Information
217217
Assert.AreEqual("9000000025", result.NhsNumber);
218-
Assert.AreEqual("2010-10-22", result.DateOfBirth);
218+
Assert.AreEqual("20101022", result.DateOfBirth);
219219
Assert.AreEqual(Gender.Female, result.Gender);
220220

221221
// Name Information
@@ -340,7 +340,7 @@ public void FhirParser_PatientWithMobileNumber_MapsCorrectly()
340340

341341
// Assert
342342
Assert.AreEqual("07700900123", result.MobileNumber);
343-
Assert.AreEqual("2020-01-01", result.MobileNumberEffectiveFromDate);
343+
Assert.AreEqual("20200101", result.MobileNumberEffectiveFromDate);
344344
}
345345

346346
[TestMethod]

0 commit comments

Comments
 (0)