Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same endpoint for download results as the results list view #8110

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package gov.cdc.usds.simplereport.api.testresult;

import gov.cdc.usds.simplereport.api.model.ApiFacility;
import gov.cdc.usds.simplereport.db.model.PatientLink;
import gov.cdc.usds.simplereport.db.model.auxiliary.ResolvedSurveyData;
import gov.cdc.usds.simplereport.db.model.auxiliary.TestResultsListItem;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.dataloader.DataLoader;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.stereotype.Controller;

Expand All @@ -12,4 +17,15 @@ public class ResultDataResolver {
public ApiFacility getFacility(TestResultsListItem result) {
return new ApiFacility(result.getFacility());
}

@SchemaMapping(typeName = "Result", field = "surveyData")
public ResolvedSurveyData getSurveyData(TestResultsListItem result) {
return new ResolvedSurveyData(result.getSurveyData());
}

@SchemaMapping(typeName = "Result", field = "patientLink")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the patientLink field? I don't think we are using it on the results page or mapping it to the CSV when we download the results 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure there was some error it ran into with the tests, but I can't remember what it specifically was so maybe that error was made obsolete by other changes, gonna test out removing that patient link then. patientLink is on the TestResult type which might be on the path to being deprecated in favor of Result now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For TestResultTest, this line expects patientLink to be there on the result. This old unit test might be left over from when we used to need the patient link on the result but maybe we no longer do? Do you think we should edit/remove the unit test or add patient link for now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh oops sorry for missing that! Thank you for looking into that again 😓 I think maybe for now we can put the patientLink field back so the tests could pass and this bug fix can be merged in. Thank you for your patience with me on this 😅 🙏

But if you think it'll be helpful, we can make a tech debt ticket to clean this up. That field doesn't seem to be used (based on my rough reading of the codebase) but probably best to dig more thoroughly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I'll create a new ticket to address some of that tech debt around TestResult vs Result overall

public CompletableFuture<PatientLink> getPatientLink(
TestResultsListItem result, DataLoader<UUID, PatientLink> patientLinkDataLoader) {
return patientLinkDataLoader.load(result.getTestOrderId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gov.cdc.usds.simplereport.db.model.auxiliary;

import java.time.LocalDate;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ResolvedSurveyData {

private String pregnancy;
private String syphilisHistory;
private String symptoms;
private Boolean noSymptoms;
private LocalDate symptomOnset;
private List<String> genderOfSexualPartners;

public ResolvedSurveyData(AskOnEntrySurvey surveyData) {
this.pregnancy = surveyData.getPregnancy();
this.syphilisHistory = surveyData.getSyphilisHistory();
this.symptoms = surveyData.getSymptomsJSON();
this.noSymptoms = surveyData.getNoSymptoms();
this.symptomOnset = surveyData.getSymptomOnsetDate();
this.genderOfSexualPartners = surveyData.getGenderOfSexualPartners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class TestResultsListItem {
private final TestCorrectionStatus correctionStatus;
private final String reasonForCorrection;
private final ApiUser createdBy;
private final AskOnEntrySurvey surveyData;
private final UUID testOrderId;

public TestResultsListItem(Result result) {
this.id = result.getTestEvent().getInternalId();
Expand All @@ -37,5 +39,7 @@ public TestResultsListItem(Result result) {
this.correctionStatus = result.getTestEvent().getCorrectionStatus();
this.reasonForCorrection = result.getTestEvent().getReasonForCorrection();
this.createdBy = result.getTestEvent().getCreatedBy();
this.surveyData = result.getTestEvent().getSurveyData();
this.testOrderId = result.getTestEvent().getTestOrderId();
}
}
11 changes: 11 additions & 0 deletions backend/src/main/resources/graphql/main.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ type TestResultsPage {
content: [TestResult]
}

type AskOnEntrySurvey {
pregnancy: String
syphilisHistory: String
symptoms: String
symptomOnset: LocalDate
noSymptoms: Boolean
genderOfSexualPartners: [String]
}

type Result {
id: ID!
facility: Facility!
Expand All @@ -321,6 +330,8 @@ type Result {
correctionStatus: String
reasonForCorrection: String
createdBy: ApiUser
surveyData: AskOnEntrySurvey
patientLink: PatientLink
}

type ResultsPage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,19 @@ void submitAndFetchMultiplexResult() {

assertTrue(testResults.has(0), "Has at least one submitted test result=");
assertEquals(dateTested, testResults.get(0).get("dateTested").asText());
assertEquals("{\"25064002\":\"true\"}", testResults.get(0).get("symptoms").asText());
assertEquals("false", testResults.get(0).get("noSymptoms").asText());
assertEquals("77386006", testResults.get(0).get("pregnancy").asText());
assertEquals("2020-09-15", testResults.get(0).get("symptomOnset").asText());
assertEquals("[\"male\"]", testResults.get(0).get("genderOfSexualPartners").toString());
assertEquals(
"{\"25064002\":\"true\"}", testResults.get(0).get("surveyData").get("symptoms").asText());
assertEquals("false", testResults.get(0).get("surveyData").get("noSymptoms").asText());
assertEquals("77386006", testResults.get(0).get("surveyData").get("pregnancy").asText());
assertEquals("2020-09-15", testResults.get(0).get("surveyData").get("symptomOnset").asText());
assertEquals(
"[\"male\"]",
testResults.get(0).get("surveyData").get("genderOfSexualPartners").toString());
testResults
.get(0)
.get("results")
.elements()
.forEachRemaining(
r -> {
switch (r.get("disease").get("name").asText()) {
switch (r.get("disease").asText()) {
case "COVID-19":
assertEquals(TestResult.NEGATIVE.toString(), r.get("testResult").asText());
break;
Expand All @@ -199,7 +200,7 @@ void submitAndFetchMultiplexResult() {
assertEquals(TestResult.UNDETERMINED.toString(), r.get("testResult").asText());
break;
default:
fail("Unexpected disease=" + r.get("disease").get("name").asText());
fail("Unexpected disease=" + r.get("disease").asText());
}
});
}
Expand Down Expand Up @@ -279,8 +280,8 @@ void testResultOperations_standardUser_successDependsOnFacilityAccess() {
updateSelfPrivileges(Role.USER, true, Set.of());
ArrayNode testResults = fetchTestResults(fetchVariables);
assertEquals(2, testResults.size());
UUID t1Id = UUID.fromString(testResults.get(0).get("internalId").asText());
UUID t2Id = UUID.fromString(testResults.get(1).get("internalId").asText());
UUID t1Id = UUID.fromString(testResults.get(0).get("id").asText());
UUID t2Id = UUID.fromString(testResults.get(1).get("id").asText());

updateSelfPrivileges(Role.USER, false, Set.of(_secondSite.getInternalId()));

Expand Down Expand Up @@ -506,13 +507,13 @@ private ObjectNode submitQueueItem(

private ArrayNode fetchTestResults(Map<String, Object> variables) {
return (ArrayNode)
runQuery("test-results-with-count-query", variables).get("testResultsPage").get("content");
runQuery("test-results-with-count-query", variables).get("resultsPage").get("content");
}

private ArrayNode fetchTestResultsMultiplex(Map<String, Object> variables) {
return (ArrayNode)
runQuery("test-results-with-count-multiplex-query", variables)
.get("testResultsPage")
.get("resultsPage")
.get("content");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
query GetFacilityResultsWithCountMultiplex(
$facilityId: ID!
) {
testResultsPage(facilityId: $facilityId) {
resultsPage(
facilityId: $facilityId
) {
content {
internalId
id
dateAdded
dateTested
results {
disease {
name
}
testResult
disease
testResult
correctionStatus
reasonForCorrection
facility {
name
isDeleted
}
deviceType {
internalId
Expand All @@ -20,18 +25,34 @@ query GetFacilityResultsWithCountMultiplex(
firstName
middleName
lastName
lookupId
birthDate
gender
role
email
phoneNumbers {
type
number
}
}
patientLink {
internalId
}
symptoms
noSymptoms
pregnancy
symptomOnset
genderOfSexualPartners
surveyData {
pregnancy
syphilisHistory
symptoms
symptomOnset
noSymptoms
genderOfSexualPartners
}
createdBy {
nameInfo {
firstName
middleName
lastName
}
}
}

totalElements
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
query GetFacilityResultsWithCount($facilityId: ID) {
testResultsPage(facilityId: $facilityId) {
resultsPage(
facilityId: $facilityId
) {
content {
internalId
id
dateAdded
dateTested
results {
disease {
internalId
name
loinc
}
testResult
disease
testResult
correctionStatus
reasonForCorrection
facility {
name
isDeleted
}
deviceType {
internalId
Expand All @@ -20,16 +23,26 @@ query GetFacilityResultsWithCount($facilityId: ID) {
firstName
middleName
lastName
lookupId
birthDate
gender
role
email
phoneNumbers {
type
number
}
}
patientLink {
internalId
}
symptoms
noSymptoms
pregnancy
symptomOnset
createdBy {
nameInfo {
firstName
middleName
lastName
}
}
}
totalElements
}
}
}
91 changes: 91 additions & 0 deletions frontend/src/app/testResults/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,97 @@ query GetResultsMultiplexWithCount(
}
}

query GetResultsForDownload(
$facilityId: ID
$patientId: ID
$result: String
$role: String
$disease: String
$startDate: DateTime
$endDate: DateTime
$pageNumber: Int
$pageSize: Int
) {
resultsPage(
facilityId: $facilityId
patientId: $patientId
result: $result
role: $role
disease: $disease
startDate: $startDate
endDate: $endDate
pageNumber: $pageNumber
pageSize: $pageSize
) {
content {
id
dateAdded
dateUpdated
dateTested
disease
testResult
correctionStatus
reasonForCorrection
facility {
name
isDeleted
}
deviceType {
name
manufacturer
model
swabTypes {
internalId,
name
}
}
patient {
firstName
middleName
lastName
birthDate
gender
race
ethnicity
tribalAffiliation
role
lookupId
street
streetTwo
city
county
state
zipCode
country
email
phoneNumbers {
type
number
}
residentCongregateSetting
employedInHealthcare
preferredLanguage
}
createdBy {
nameInfo {
firstName
middleName
lastName
}
}
surveyData {
pregnancy
syphilisHistory
symptoms
symptomOnset
noSymptoms
genderOfSexualPartners
}
}
totalElements
}
}

query GetAllFacilities($showArchived: Boolean) {
facilities(showArchived: $showArchived) {
id
Expand Down
Loading
Loading