Skip to content

Commit

Permalink
Merge branch 'main' into nick/upgrade-react-router
Browse files Browse the repository at this point in the history
  • Loading branch information
nickclyde committed Feb 8, 2022
2 parents 1afbec1 + 0e18668 commit 7ab6b91
Show file tree
Hide file tree
Showing 20 changed files with 402 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rollbackDB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.15.1
terraform_version: 1.1.4
- name: Terraform init
run: make init-${{ env.DEPLOY_ENV }}
- name: Launch DB Rollback Container Instance
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ To do so manually:
Example:

```Shell
MAINTENANCE_MESSAGE='{"active": true, "message": "SimpleReport is currently experiencing service degradation"}' MAINTENANCE_ENV=dev yarn run maintenance:start
MAINTENANCE_MESSAGE='{"active": true, "header" : "SimpleReport is currently experiencing an outage.", "message": "SimpleReport is currently experiencing service degradation"}' MAINTENANCE_ENV=dev yarn run maintenance:start
```

Possible values for `MAINTENANCE_ENV`: `dev`, `test`, `pentest`, `training`, `demo`, `stg`, `prod`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ public String getCorrectedResultId() {
return "";
}

@JsonProperty("Test_correction_reason")
public String getCorrectionReason() {
if (testEvent.getCorrectionStatus() != TestCorrectionStatus.ORIGINAL) {
return Optional.ofNullable(testEvent.getReasonForCorrection()).orElse("");
}
return "";
}

// 27Jan2021 Updated to handle deleted tests
@JsonProperty("Test_result_status")
public String getTestResultStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public TestEvent correctTestMarkAsError(UUID testEventId, String reasonForCorrec
TestEvent newRemoveEvent =
new TestEvent(event, TestCorrectionStatus.REMOVED, reasonForCorrection);
_terepo.save(newRemoveEvent);
_testEventReportingService.report(newRemoveEvent);

// order having reason text is way more useful when we allow actual corrections
// not just
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestEventExportIntegrationTest extends BaseGraphqlTest {
@MockBean private CurrentTenantDataAccessContextHolder _tenantDataAccessContextHolder;
private final ObjectMapper objectMapper = new ObjectMapper();

TestEventExport testEventExport;
private TestEvent testEvent;

@BeforeEach
void initData() {
Expand All @@ -56,12 +56,12 @@ void initData() {
.put("dateTested", "2021-09-01T10:31:30.001Z");
submitTestResult(variables, Optional.empty());
// getting the testEvent can be improve to use the same context as used by the uploader
TestEvent testEvent = _testEventService.getLastTestResultsForPatient(patient);
testEventExport = new TestEventExport(testEvent);
testEvent = _testEventService.getLastTestResultsForPatient(patient);
}

@Test
void testEventSerialization() throws Exception {
TestEventExport testEventExport = new TestEventExport(testEvent);
JSONAssert.assertEquals(
"{"
+ "\"Patient_last_name\":\"Astaire\","
Expand Down Expand Up @@ -92,6 +92,7 @@ void testEventSerialization() throws Exception {
+ testEventExport.getResultID()
+ ","
+ "\"Corrected_result_ID\":\"\","
+ "\"Test_correction_reason\":\"\","
+ "\"Test_result_status\":\"F\","
+ "\"Test_result_code\":\"260415000\","
+ "\"Specimen_collection_date_time\":\""
Expand Down Expand Up @@ -152,6 +153,105 @@ void testEventSerialization() throws Exception {
false);
}

@Test
void testCorrectedEventSerialization() throws Exception {
TestEvent correctedTestEvent = _dataFactory.createTestEventCorrection(testEvent);
TestEventExport correctedTestEventExport = new TestEventExport(correctedTestEvent);

String actualStr = objectMapper.writeValueAsString(correctedTestEventExport);
JSONAssert.assertEquals(
"{"
+ "\"Patient_last_name\":\"Astaire\","
+ "\"Patient_first_name\":\"Fred\","
+ "\"Patient_middle_name\":null,"
+ "\"Patient_suffix\":null,"
+ "\"Patient_race\":\"2106-3\","
+ "\"Patient_DOB\":\"18990510\","
+ "\"Patient_gender\":\"M\","
+ "\"Patient_ethnicity\":\"N\","
+ "\"Patient_street\":\"736 Jackson PI NW\","
+ "\"Patient_street_2\":\"\","
+ "\"Patient_city\":\"Washington\","
+ "\"Patient_county\":\"Washington\","
+ "\"Patient_state\":\"DC\","
+ "\"Patient_zip_code\":\"20503\","
+ "\"Patient_phone_number\":\"202-123-4567\","
+ "\"Patient_email\":\"[email protected]\","
+ "\"Patient_ID\":"
+ correctedTestEventExport.getPatientId()
+ ","
+ "\"Patient_role\":\"RESIDENT\","
+ "\"Patient_tribal_affiliation\":\"\","
+ "\"Patient_preferred_language\":\"English\","
+ "\"Employed_in_healthcare\":\"N\","
+ "\"Resident_congregate_setting\":\"N\","
+ "\"Result_ID\":"
+ correctedTestEventExport.getResultID()
+ ","
+ "\"Corrected_result_ID\":\""
+ testEvent.getInternalId().toString()
+ "\","
+ "\"Test_correction_reason\":\"Cold feet\","
+ "\"Test_result_status\":\"C\","
+ "\"Test_result_code\":\"260415000\","
+ "\"Specimen_collection_date_time\":\""
+ correctedTestEventExport.getSpecimenCollectionDateTime()
+ "\","
+ "\"Ordering_provider_ID\":\"PEBBLES\","
+ "\"First_test\":\"UNK\","
+ "\"Symptomatic_for_disease\":\"UNK\","
+ "\"Illness_onset_date\":\"\","
+ "\"Testing_lab_name\":\"Injection Site\","
+ "\"Testing_lab_CLIA\":\"000111222-3\","
+ "\"Testing_lab_state\":null,"
+ "\"Testing_lab_street\":\"2797 N Cerrada de Beto\","
+ "\"Testing_lab_street_2\":\"\","
+ "\"Testing_lab_zip_code\":null,"
+ "\"Testing_lab_county\":null,"
+ "\"Testing_lab_phone_number\":null,"
+ "\"Testing_lab_city\":null,"
+ "\"Processing_mode_code\":\"P\","
+ "\"Ordering_facility_city\":null,"
+ "\"Ordering_facility_county\":null,"
+ "\"Ordering_facility_name\":\"Injection Site\","
+ "\"Organization_name\":\"Dis Organization\","
+ "\"Ordering_facility_phone_number\":null,"
+ "\"Ordering_facility_email\":null,"
+ "\"Ordering_facility_state\":null,"
+ "\"Ordering_facility_street\":\"2797 N Cerrada de Beto\","
+ "\"Ordering_facility_street_2\":\"\","
+ "\"Ordering_facility_zip_code\":null,"
+ "\"Ordering_provider_last_name\":\"Flintstone\","
+ "\"Ordering_provider_first_name\":\"Fred\","
+ "\"Ordering_provider_street\":\"123 Main Street\","
+ "\"Ordering_provider_street_2\":\"\","
+ "\"Ordering_provider_city\":\"Oz\","
+ "\"Ordering_provider_state\":\"KS\","
+ "\"Ordering_provider_zip_code\":null,"
+ "\"Ordering_provider_county\":null,"
+ "\"Ordering_provider_phone_number\":\"(202) 555-1212\","
+ "\"Ordered_test_code\":\"95209-3\","
+ "\"Specimen_source_site_code\":\"71836000\","
+ "\"Specimen_type_code\":\"445297001\","
+ "\"Instrument_ID\":"
+ correctedTestEventExport.getInstrumentID()
+ ","
+ "\"Device_ID\":\"LumiraDx SARS-CoV-2 Ag Test*\","
+ "\"Test_date\":\""
+ correctedTestEventExport.getTestDate()
+ "\","
+ "\"Date_result_released\":\""
+ correctedTestEventExport.getDateResultReleased()
+ "\","
+ "\"Order_test_date\":\""
+ correctedTestEventExport.getOrderTestDate()
+ "\","
+ "\"Site_of_care\":\"university\""
+ "}",
actualStr,
false);
}

private JsonNode submitTestResult(ObjectNode variables, Optional<String> expectedError) {
return runQuery("add-test-result-mutation", variables, expectedError.orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import gov.cdc.usds.simplereport.test_util.TestDataFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collections;
import java.util.Date;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
Expand Down Expand Up @@ -168,4 +171,27 @@ void specimenCollectionSubtractsDeviceOffset() throws ParseException {
assertEquals("20201215000000", sut.getTestDate());
assertEquals("20201214234500", sut.getSpecimenCollectionDateTime());
}

@Test
void sendCorrectionReason() {
// GIVEN
Organization org = _dataFactory.createValidOrg();
Facility facility = _dataFactory.createValidFacility(org);
Person person = _dataFactory.createFullPerson(org);

LocalDate localDate = LocalDate.of(2020, 7, 23);
Date backTestedDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
TestEvent originalTestEvent =
_dataFactory.createTestEvent(person, facility, null, null, backTestedDate);
String originalEventId = originalTestEvent.getInternalId().toString();
TestEvent testEvent = _dataFactory.createTestEventCorrection(originalTestEvent);

// WHEN
TestEventExport exportedEvent = new TestEventExport(testEvent);

// THEN
assertEquals("20200723000000", exportedEvent.getTestDate());
assertEquals("Cold feet", exportedEvent.getCorrectionReason());
assertEquals(originalEventId, exportedEvent.getCorrectedResultId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -52,6 +53,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
Expand All @@ -68,6 +70,8 @@ class TestOrderServiceTest extends BaseServiceTest<TestOrderService> {
@Autowired private TestDataFactory _dataFactory;
@SpyBean private PatientLinkService patientLinkService;
@MockBean private TestResultsDeliveryService testResultsDeliveryService;
@MockBean TestEventReportingService testEventReportingService;
@Captor ArgumentCaptor<TestEvent> testEventArgumentCaptor;

private static final PersonName AMOS = new PersonName("Amos", null, "Quint", null);
private static final PersonName BRAD = new PersonName("Bradley", "Z.", "Jones", "Jr.");
Expand All @@ -93,9 +97,10 @@ void setupData() {
@Test
@WithSimpleReportOrgAdminUser
void roundTrip() {
// GIVEN
Facility facility =
_dataFactory.createValidFacility(_organizationService.getCurrentOrganization());
Person p =
Person patient =
_personService.addPatient(
(UUID) null,
"FOO",
Expand All @@ -119,22 +124,36 @@ void roundTrip() {
null);

_service.addPatientToQueue(
facility.getInternalId(), p, "", Collections.emptyMap(), LocalDate.of(1865, 12, 25), false);
facility.getInternalId(),
patient,
"",
Collections.emptyMap(),
LocalDate.of(1865, 12, 25),
false);
DeviceSpecimenType devA = facility.getDefaultDeviceSpecimen();

List<TestOrder> queue = _service.getQueue(facility.getInternalId());
assertEquals(1, queue.size());

DeviceSpecimenType devA = facility.getDefaultDeviceSpecimen();
_service.addTestResult(devA.getInternalId(), TestResult.POSITIVE, p.getInternalId(), null);
// WHEN
_service.addTestResult(
devA.getInternalId(), TestResult.POSITIVE, patient.getInternalId(), null);

// THEN
queue = _service.getQueue(facility.getInternalId());
assertEquals(0, queue.size());

List<TestEvent> testEvents =
_testEventRepository.findAllByPatientAndFacilities(p, List.of(facility));
_testEventRepository.findAllByPatientAndFacilities(patient, List.of(facility));
assertThat(testEvents).hasSize(1);
assertThat(testEvents.get(0).getPatientHasPriorTests()).isFalse();
verify(patientLinkService).createPatientLink(any());

// make sure the corrected event is sent to storage queue
verify(testEventReportingService).report(testEventArgumentCaptor.capture());
TestEvent sentEvent = testEventArgumentCaptor.getValue();
assertThat(sentEvent.getPatient().getInternalId()).isEqualTo(patient.getInternalId());
assertThat(sentEvent.getResult()).isEqualTo(TestResult.POSITIVE);
}

@Test
Expand Down Expand Up @@ -173,6 +192,8 @@ void addTestResult_populateFirstTest() {
p.getInternalId(),
null);

verify(testEventReportingService, times(1)).report(any());

List<TestEvent> testEvents =
_testEventRepository.findAllByPatientAndFacilities(p, List.of(facility));
assertThat(testEvents).hasSize(1);
Expand All @@ -190,6 +211,7 @@ void addTestResult_populateFirstTest() {
assertThat(testEvents).hasSize(2);
assertThat(testEvents.get(0).getPatientHasPriorTests()).isFalse();
assertThat(testEvents.get(1).getPatientHasPriorTests()).isTrue();
verify(testEventReportingService, times(2)).report(any());
}

@Test
Expand Down Expand Up @@ -330,6 +352,7 @@ void addTestResult_orgAdmin_ok() {

List<TestOrder> queue = _service.getQueue(facility.getInternalId());
assertEquals(0, queue.size());
verify(testEventReportingService).report(any());
}

@Test
Expand Down Expand Up @@ -367,6 +390,7 @@ void addTestResult_standardUserAllFacilities_ok() {

List<TestOrder> queue = _service.getQueue(facility.getInternalId());
assertEquals(0, queue.size());
verify(testEventReportingService).report(any());
}

@Test
Expand All @@ -375,9 +399,6 @@ void addTestResult_standardUser_successDependsOnFacilityAccess() {
Facility facility1 =
_dataFactory.createValidFacility(
_organizationService.getCurrentOrganization(), "First One");
Facility facility2 =
_dataFactory.createValidFacility(
_organizationService.getCurrentOrganization(), "Second One");

TestUserIdentities.setFacilityAuthorities(facility1);

Expand Down Expand Up @@ -458,15 +479,24 @@ void addTestResult_standardUser_successDependsOnFacilityAccess() {
_service.addTestResult(
devA.getInternalId(), TestResult.POSITIVE, p1.getInternalId(), null));

// make sure the nothing was sent to storage queue
verifyNoInteractions(testEventReportingService);

TestUserIdentities.setFacilityAuthorities(facility1);
_service.addTestResult(devA.getInternalId(), TestResult.POSITIVE, p1.getInternalId(), null);
List<TestOrder> queue = _service.getQueue(facility1.getInternalId());
assertEquals(1, queue.size());

// make sure the corrected event is sent to storage queue
verify(testEventReportingService).report(any());

_service.addTestResult(devA.getInternalId(), TestResult.NEGATIVE, p2.getInternalId(), null);

queue = _service.getQueue(facility1.getInternalId());
assertEquals(0, queue.size());

// make sure the second event is sent to storage queue
verify(testEventReportingService, times(2)).report(any());
}

@Test
Expand Down Expand Up @@ -715,6 +745,7 @@ void addTestResult_NoTestResultDelivery() {
// THEN
assertTrue(res.getDeliverySuccess());
verifyNoInteractions(testResultsDeliveryService);
verify(testEventReportingService).report(any());
}

@Test
Expand Down Expand Up @@ -1069,6 +1100,10 @@ void correctionsTest() {
assertEquals(
deleteMarkerEvent.getInternalId().toString(),
events_after.get(0).getInternalId().toString());

// make sure the corrected event is sent to storage queue, which gets picked up to be delivered
// to report stream
verify(testEventReportingService).report(deleteMarkerEvent);
}

@Test
Expand Down Expand Up @@ -1396,9 +1431,14 @@ void correctionsTest_successDependsOnFacilityAccess() {
AccessDeniedException.class,
() -> _service.getTestResult(_e.getInternalId()).getTestOrder());

// make sure the corrected event is not sent to storage queue
verifyNoInteractions(testEventReportingService);

TestUserIdentities.setFacilityAuthorities(facility);
_service.correctTestMarkAsError(_e.getInternalId(), reasonMsg);
TestEvent correctedTestEvent = _service.correctTestMarkAsError(_e.getInternalId(), reasonMsg);
_service.getTestEventsResults(facility.getInternalId(), null, null, null, null, null, 0, 10);
_service.getTestResult(_e.getInternalId()).getTestOrder();
// make sure the corrected event is sent to storage queue
verify(testEventReportingService).report(correctedTestEvent);
}
}
Loading

0 comments on commit 7ab6b91

Please sign in to comment.