Skip to content

Commit

Permalink
Use same endpoint for download results as the results list view (#8110)
Browse files Browse the repository at this point in the history
* Add survey data on TestResultsListItem

* Use GetResultsForDownload query for csv download

* Add resolved survey data

* Use SymptomOnset instead of SymptomOnsetDate

* Add resolved patient link

* Update TestResultTest

* Update codegen graphql

* Filter disabled diseases on csv download
  • Loading branch information
mpbrown authored Sep 23, 2024
1 parent a63182a commit 00710d9
Show file tree
Hide file tree
Showing 14 changed files with 761 additions and 274 deletions.
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")
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

0 comments on commit 00710d9

Please sign in to comment.