Skip to content

Commit

Permalink
Fix default datetime values for test result upload - covid pipeline (#…
Browse files Browse the repository at this point in the history
…7132)

* Fix default datetime values for test result upload - covid pipeline

* Address daylight savings time in test
  • Loading branch information
emyl3 authored Jan 3, 2024
1 parent a6b9413 commit 16f7bdc
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ZoneId getZoneIdByLookup(Lookup lookup) {
try {
timezoneInfo = getTimezoneInfoByLookup(lookup);
} catch (InvalidAddressException | IllegalGraphqlArgumentException exception) {
log.error("Unable to find timezone by testing lab address", exception);
log.error("Unable to find timezone with provided address", exception);
}
if (timezoneInfo == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ private Map<String, String> transformCsvRow(Map<String, String> row) {
var updatedSpecimenType =
modifyRowSpecimenNameToSNOMED(row.get(SPECIMEN_TYPE_COLUMN_NAME).toLowerCase());

var testingLabAddress =
new StreetAddress(
row.get("testing_lab_street"),
row.get("testing_lab_street2"),
row.get("testing_lab_city"),
row.get("testing_lab_state"),
row.get("testing_lab_zip_code"),
null);
var providerAddress =
new StreetAddress(
row.get("ordering_provider_street"),
Expand All @@ -255,9 +247,7 @@ private Map<String, String> transformCsvRow(Map<String, String> row) {

var testResultDate =
convertToZonedDateTime(
row.get(TEST_RESULT_DATE_COLUMN_NAME),
resultsUploaderCachingService,
testingLabAddress);
row.get(TEST_RESULT_DATE_COLUMN_NAME), resultsUploaderCachingService, providerAddress);

var orderTestDate =
convertToZonedDateTime(
Expand All @@ -276,15 +266,15 @@ private Map<String, String> transformCsvRow(Map<String, String> row) {
? convertToZonedDateTime(
row.get(TESTING_LAB_SPECIMEN_RECEIVED_DATE_COLUMN_NAME),
resultsUploaderCachingService,
testingLabAddress)
providerAddress)
: orderTestDate;

var dateResultReleased =
StringUtils.isNotBlank(row.get(DATE_RESULT_RELEASED_COLUMN_NAME))
? convertToZonedDateTime(
row.get(DATE_RESULT_RELEASED_COLUMN_NAME),
resultsUploaderCachingService,
testingLabAddress)
providerAddress)
: testResultDate;

row.put(SPECIMEN_TYPE_COLUMN_NAME, updatedSpecimenType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gov.cdc.usds.simplereport.db.model.TestResultUpload;
import gov.cdc.usds.simplereport.db.model.auxiliary.FHIRBundleRecord;
import gov.cdc.usds.simplereport.db.model.auxiliary.Pipeline;
import gov.cdc.usds.simplereport.db.model.auxiliary.StreetAddress;
import gov.cdc.usds.simplereport.db.model.auxiliary.UploadStatus;
import gov.cdc.usds.simplereport.db.repository.ResultUploadErrorRepository;
import gov.cdc.usds.simplereport.db.repository.TestResultUploadRepository;
Expand All @@ -47,6 +48,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -708,6 +711,77 @@ void uploadService_processCsv_handlesEscapedCommas_inTestingLabValues() {
assertThat(row.getTestingLabPhoneNumber().getValue()).isEqualTo("205-888-2000");
}

@Test
@SliceTestConfiguration.WithSimpleReportStandardUser
void uploadService_processCsv_handlesDefaultDateTimeZone_withValidOrderingProviderAddress() {
// GIVEN
ZoneId zoneId = ZoneId.of("US/Pacific");
InputStream input = loadCsv("testResultUpload/test-results-upload-valid-default-dates.csv");
UploadResponse response = buildUploadResponse();
when(dataHubMock.uploadCSV(any())).thenReturn(response);
when(resultsUploaderCachingServiceMock.getSpecimenTypeNameToSNOMEDMap())
.thenReturn(Map.of("nasal swab", "000111222"));
when(resultsUploaderCachingServiceMock.getCovidEquipmentModelAndTestPerformedCodeSet())
.thenReturn(Set.of(ResultsUploaderCachingService.getKey("ID NOW", "94534-5")));
StreetAddress providerAddress =
new StreetAddress("400 Main Street", "", "Hayward", "CA", "94540", null);
when(resultsUploaderCachingServiceMock.getZoneIdByAddress(providerAddress)).thenReturn(zoneId);
when(repoMock.save(any())).thenReturn(mock(TestResultUpload.class));

// WHEN
sut.processResultCSV(input);

// THEN
TestResultRow row = getRowFromUpload(dataHubMock);
String expectedTestResultDateTime =
ZonedDateTime.of(2021, 12, 23, 12, 0, 0, 0, zoneId).toOffsetDateTime().toString();
String expectedOrderTestDateTime =
ZonedDateTime.of(2021, 12, 20, 12, 0, 0, 0, zoneId).toOffsetDateTime().toString();
assertThat(row.getTestResultDate().getValue()).isEqualTo(expectedTestResultDateTime);
assertThat(row.getOrderTestDate().getValue()).isEqualTo(expectedOrderTestDateTime);
assertThat(row.getSpecimenCollectionDate().getValue()).isEqualTo(expectedOrderTestDateTime);
assertThat(row.getTestingLabSpecimenReceivedDate().getValue())
.isEqualTo(expectedOrderTestDateTime);
assertThat(row.getDateResultReleased().getValue()).isEqualTo(expectedTestResultDateTime);
}

@Test
@SliceTestConfiguration.WithSimpleReportStandardUser
void uploadService_processCsv_defaultsToEasternTimeZone_withInvalidOrderingProviderAddress() {
// GIVEN
InputStream input = loadCsv("testResultUpload/test-results-upload-valid-default-dates.csv");
UploadResponse response = buildUploadResponse();
when(dataHubMock.uploadCSV(any())).thenReturn(response);
when(resultsUploaderCachingServiceMock.getSpecimenTypeNameToSNOMEDMap())
.thenReturn(Map.of("nasal swab", "000111222"));
when(resultsUploaderCachingServiceMock.getCovidEquipmentModelAndTestPerformedCodeSet())
.thenReturn(Set.of(ResultsUploaderCachingService.getKey("ID NOW", "94534-5")));
StreetAddress providerAddress =
new StreetAddress("400 Main Street", "", "Hayward", "CA", "94540", null);
when(resultsUploaderCachingServiceMock.getZoneIdByAddress(providerAddress)).thenReturn(null);
when(repoMock.save(any())).thenReturn(mock(TestResultUpload.class));

// WHEN
sut.processResultCSV(input);

// THEN
TestResultRow row = getRowFromUpload(dataHubMock);
String expectedTestResultDateTime =
ZonedDateTime.of(2021, 12, 23, 12, 0, 0, 0, ZoneId.of("US/Eastern"))
.toOffsetDateTime()
.toString();
String expectedOrderTestDateTime =
ZonedDateTime.of(2021, 12, 20, 12, 0, 0, 0, ZoneId.of("US/Eastern"))
.toOffsetDateTime()
.toString();
assertThat(row.getTestResultDate().getValue()).isEqualTo(expectedTestResultDateTime);
assertThat(row.getOrderTestDate().getValue()).isEqualTo(expectedOrderTestDateTime);
assertThat(row.getSpecimenCollectionDate().getValue()).isEqualTo(expectedOrderTestDateTime);
assertThat(row.getTestingLabSpecimenReceivedDate().getValue())
.isEqualTo(expectedOrderTestDateTime);
assertThat(row.getDateResultReleased().getValue()).isEqualTo(expectedTestResultDateTime);
}

@Test
@SliceTestConfiguration.WithSimpleReportStandardUser
void uploadService_processCsv_transforms_match_expected_csv() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -538,13 +539,14 @@ void convertExistingCsv_populatesBlankFields() {

@Test
void convertExistingCsv_setsOrderingProviderTimezone_forNoTimezoneInDates() {
when(resultsUploaderCachingService.getZoneIdByAddress(any()))
.thenReturn(ZoneId.of("US/Mountain"));
ZoneId zoneId = ZoneId.of("US/Mountain");
when(resultsUploaderCachingService.getZoneIdByAddress(any())).thenReturn(zoneId);
InputStream input = loadCsv("testResultUpload/test-results-upload-valid-dates-no-timezone.csv");

Instant orderTestDate = Instant.parse("2021-12-19T12:00:00-07:00");
Instant specimenCollectionDate = Instant.parse("2021-12-20T12:00:00-07:00");
Instant testResultDate = Instant.parse("2021-12-23T12:00:00-07:00");
Instant orderTestDate = ZonedDateTime.of(2021, 12, 19, 12, 0, 0, 0, zoneId).toInstant();
Instant specimenCollectionDate =
ZonedDateTime.of(2021, 12, 20, 12, 0, 0, 0, zoneId).toInstant();
Instant testResultDate = ZonedDateTime.of(2021, 12, 23, 12, 0, 0, 0, zoneId).toInstant();

FHIRBundleRecord bundleRecord = sut.convertToFhirBundles(input, UUID.randomUUID());
var serializedBundles = bundleRecord.serializedBundle();
Expand Down Expand Up @@ -574,13 +576,15 @@ void convertExistingCsv_setsOrderingProviderTimezone_forNoTimezoneInDates() {

@Test
void convertExistingCsv_setsEasternTimeDefaultTimeZone_forIncorrectOrderingProviderAddress() {
ZoneId zoneId = ZoneId.of("US/Eastern");
// mock invalid address response
when(resultsUploaderCachingService.getZoneIdByAddress(any())).thenReturn(null);
InputStream input = loadCsv("testResultUpload/test-results-upload-valid-dates-no-timezone.csv");

Instant orderTestDate = Instant.parse("2021-12-19T12:00:00-05:00");
Instant specimenCollectionDate = Instant.parse("2021-12-20T12:00:00-05:00");
Instant testResultDate = Instant.parse("2021-12-23T12:00:00-05:00");
Instant orderTestDate = ZonedDateTime.of(2021, 12, 19, 12, 0, 0, 0, zoneId).toInstant();
Instant specimenCollectionDate =
ZonedDateTime.of(2021, 12, 20, 12, 0, 0, 0, zoneId).toInstant();
Instant testResultDate = ZonedDateTime.of(2021, 12, 23, 12, 0, 0, 0, zoneId).toInstant();

FHIRBundleRecord bundleRecord = sut.convertToFhirBundles(input, UUID.randomUUID());
var serializedBundles = bundleRecord.serializedBundle();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
patient_id,patient_last_name,patient_first_name,patient_middle_name,patient_street,patient_street2,patient_city,patient_state,patient_zip_code,patient_county,patient_phone_number,patient_dob,patient_gender,patient_race,patient_ethnicity,patient_preferred_language,patient_email,accession_number,equipment_model_name,test_performed_code,test_result,order_test_date,specimen_collection_date,testing_lab_specimen_received_date,test_result_date,date_result_released,specimen_type,ordering_provider_id,ordering_provider_last_name,ordering_provider_first_name,ordering_provider_middle_name,ordering_provider_street,ordering_provider_street2,ordering_provider_city,ordering_provider_state,ordering_provider_zip_code,ordering_provider_phone_number,testing_lab_clia,testing_lab_name,testing_lab_street,testing_lab_street2,testing_lab_city,testing_lab_state,testing_lab_zip_code,testing_lab_phone_number,pregnant,employed_in_healthcare,symptomatic_for_disease,illness_onset_date,resident_congregate_setting,residence_type,hospitalized,icu,ordering_facility_name,ordering_facility_street,ordering_facility_street2,ordering_facility_city,ordering_facility_state,ordering_facility_zip_code,ordering_facility_phone_number,comment,test_result_status
1234,Doe,Jane,,123 Main St,,Birmingham,AL,35226,Jefferson,205-999-2800,1/20/1962,F,White,Not Hispanic or Latino,,,123,ID NOW,94534-5,Detected,12/20/2021,"","",12/23/2021,"",Nasal Swab,1013012657,Smith MD,John,,400 Main Street,,Hayward,CA,94540,205-888-2000,01D1058442,"My Testing Lab, Downtown Office",300 North Street,,Birmingham,AL,35228,205-888-2000,N,N,N,,N,,N,N,My Urgent Care,400 Main Street,Suite 100,Culver City,CA,90066,205-888-2000,Test Comment,F

0 comments on commit 16f7bdc

Please sign in to comment.