Skip to content

Commit

Permalink
add genderOfSexualPartners aoe question support to backend (#6896)
Browse files Browse the repository at this point in the history
* add genderOfSexualPartners aoe question support to backend

* add graphql resolver

* update graphql codegen

* add more test coverage

* add more test coverage

* add more coverage

* refactor code

* clean up

* clean up

* add back lazy loading to test
  • Loading branch information
zdeveloper authored Nov 14, 2023
1 parent a534ca0 commit f955485
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ public static String parseState(String s) {
}

public static Map<String, Boolean> parseSymptoms(String symptoms) {
if (symptoms == null) {
return Collections.emptyMap();
}
Map<String, Boolean> symptomsMap = new HashMap<String, Boolean>();
JSONObject symptomsJSONObject = new JSONObject(symptoms);
Iterator<?> keys = symptomsJSONObject.keys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ public Set<Observation> convertToAOEObservations(
Boolean symptomatic = null;
if (Boolean.TRUE.equals(surveyData.getNoSymptoms())) {
symptomatic = false;
} else if (surveyData.getSymptoms().containsValue(Boolean.TRUE)) {
} else if (surveyData.getSymptoms() != null
&& surveyData.getSymptoms().containsValue(Boolean.TRUE)) {
symptomatic = true;
} // implied else: AoE form was not completed. Symptomatic set to null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gov.cdc.usds.simplereport.db.repository.PatientAnswersRepository;
import gov.cdc.usds.simplereport.db.repository.PersonRepository;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -88,6 +89,14 @@ public CompletableFuture<LocalDate> symptomOnset(
.thenApply(patientAnswers -> patientAnswers.getSurvey().getSymptomOnsetDate());
}

@SchemaMapping(typeName = "TestOrder", field = "genderOfSexualPartners")
public CompletableFuture<List<String>> genderOfSexualPartners(
ApiTestOrder apiTestOrder, DataLoader<UUID, PatientAnswers> loader) {
return loader
.load(apiTestOrder.getWrapped().getPatientAnswersId())
.thenApply(patientAnswers -> patientAnswers.getSurvey().getGenderOfSexualPartners());
}

@SchemaMapping(typeName = "TestOrder", field = "deviceType")
public DeviceType deviceType(ApiTestOrder apiTestOrder) {
return apiTestOrder.getWrapped().getDeviceType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ public void updateTimeOfTestQuestions(
@Argument String symptoms,
@Argument LocalDate symptomOnset,
@Argument Boolean noSymptoms,
@Argument List<String> genderOfSexualPartners,
@Argument TestResultDeliveryPreference testResultDelivery) {

Map<String, Boolean> symptomsMap = parseSymptoms(symptoms);

testOrderService.updateTimeOfTestQuestions(
patientId, pregnancy, symptomsMap, symptomOnset, noSymptoms);
patientId, pregnancy, symptomsMap, symptomOnset, noSymptoms, genderOfSexualPartners);

personService.updateTestResultDeliveryPreference(patientId, testResultDelivery);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gov.cdc.usds.simplereport.db.repository.PatientLinkRepository;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -84,6 +85,11 @@ public LocalDate getSymptomOnset(TestEvent testEvent) {
return getSurvey(testEvent).getSymptomOnsetDate();
}

@SchemaMapping(typeName = "TestResult", field = "genderOfSexualPartners")
public List<String> getGenderOfSexualPartners(TestEvent testEvent) {
return getSurvey(testEvent).getGenderOfSexualPartners();
}

@SchemaMapping(typeName = "TestResult", field = "facility")
public ApiFacility getFacility(TestEvent testEvent) {
return new ApiFacility(testEvent.getFacility());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,55 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.json.JSONObject;

/**
* A representation of the questions we ask on test entry, somewhat but not excessively flexibly
* arranged to be stored and retrieved as a JSON object.
*/
@Getter
@Setter
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AskOnEntrySurvey {

private String pregnancy;
private Map<String, Boolean> symptoms;
private Boolean noSymptoms;
private LocalDate symptomOnsetDate;
private List<String> genderOfSexualPartners;

public AskOnEntrySurvey(
String pregnancy,
Map<String, Boolean> symptoms,
Boolean noSymptoms,
LocalDate symptomOnsetDate) {
LocalDate symptomOnsetDate,
List<String> genderOfSexualPartners) {
this.pregnancy = pregnancy;
this.symptoms = new HashMap<>(symptoms);
this.symptoms = (symptoms != null && symptoms.isEmpty()) ? null : symptoms;
this.noSymptoms = noSymptoms;
this.symptomOnsetDate = symptomOnsetDate;
}

public String getPregnancy() {
return pregnancy;
}

public void setPregnancy(String pregnancy) {
this.pregnancy = pregnancy;
}

public Map<String, Boolean> getSymptoms() {
return symptoms;
this.genderOfSexualPartners = genderOfSexualPartners;
}

@JsonIgnore
public String getSymptomsJSON() {
Map<String, Boolean> s = getSymptoms();

if (s == null) return null;

JSONObject obj = new JSONObject();
for (Map.Entry<String, Boolean> entry : s.entrySet()) {
obj.put(entry.getKey(), entry.getValue().toString());
}
return obj.toString();
}

public void setSymptoms(Map<String, Boolean> symptoms) {
this.symptoms = symptoms;
}

public Boolean getNoSymptoms() {
return noSymptoms;
}

public void setNoSymptoms(Boolean noSymptoms) {
this.noSymptoms = noSymptoms;
}

public LocalDate getSymptomOnsetDate() {
return symptomOnsetDate;
}

public void setSymptomOnsetDate(LocalDate symptomOnsetDate) {
this.symptomOnsetDate = symptomOnsetDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,24 +469,17 @@ public void updateTimeOfTestQuestions(
String pregnancy,
Map<String, Boolean> symptoms,
LocalDate symptomOnsetDate,
Boolean noSymptoms) {
TestOrder order = retrieveTestOrder(patientId);
Boolean noSymptoms,
List<String> genderOfSexualPartners) {

updateTimeOfTest(order, pregnancy, symptoms, symptomOnsetDate, noSymptoms);
}

private void updateTimeOfTest(
TestOrder order,
String pregnancy,
Map<String, Boolean> symptoms,
LocalDate symptomOnsetDate,
Boolean noSymptoms) {
TestOrder order = retrieveTestOrder(patientId);
PatientAnswers answers = order.getAskOnEntrySurvey();
AskOnEntrySurvey survey = answers.getSurvey();
survey.setPregnancy(pregnancy);
survey.setSymptoms(symptoms);
survey.setNoSymptoms(noSymptoms);
survey.setSymptomOnsetDate(symptomOnsetDate);
survey.setGenderOfSexualPartners(genderOfSexualPartners);
answers.setSurvey(survey);
_patientAnswersRepo.save(answers);
}
Expand Down
3 changes: 3 additions & 0 deletions backend/src/main/resources/graphql/main.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ type TestOrder {
noSymptoms: Boolean
symptoms: String
symptomOnset: LocalDate
genderOfSexualPartners: [String]
deviceType: DeviceType!
specimenType: SpecimenType!
results: [MultiplexResult!]!
Expand All @@ -278,6 +279,7 @@ type TestResult {
noSymptoms: Boolean
symptoms: String
symptomOnset: LocalDate
genderOfSexualPartners: [String]
deviceType: DeviceType
results: [MultiplexResult]
dateTested: DateTime
Expand Down Expand Up @@ -672,6 +674,7 @@ type Mutation {
symptoms: String @Size(min: 0, max: 1024)
symptomOnset: LocalDate
noSymptoms: Boolean
genderOfSexualPartners: [String]
testResultDelivery: TestResultDeliveryPreference
): String @requiredPermissions(allOf: ["UPDATE_TEST"])
sendPatientLinkSms(internalId: ID!): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ void convertToObservation_Result_correctionMatchesJson() throws IOException {

@Test
void convertToAoeObservation_noSymptoms_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), true, null);
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), true, null, null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, null, null);
Expand All @@ -965,7 +965,8 @@ void convertToAoeObservation_noSymptoms_matchesJson() throws IOException {

@Test
void convertToAoeObservation_symptomatic_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey(null, Map.of("fake", true), false, LocalDate.of(2023, 3, 4));
var answers =
new AskOnEntrySurvey(null, Map.of("fake", true), false, LocalDate.of(2023, 3, 4), null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, null, null);
Expand All @@ -984,7 +985,7 @@ void convertToAoeObservation_symptomatic_matchesJson() throws IOException {

@Test
void convertToAoeObservation_employedInHealthcare_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), null, null);
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), null, null, null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, true, null);
Expand All @@ -1003,7 +1004,7 @@ void convertToAoeObservation_employedInHealthcare_matchesJson() throws IOExcepti

@Test
void convertToAoeObservation_residesInCongregateSetting_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), null, null);
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), null, null, null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, null, true);
Expand All @@ -1022,7 +1023,7 @@ void convertToAoeObservation_residesInCongregateSetting_matchesJson() throws IOE

@Test
void convertToAoeObservation_pregnancyStatus_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey("77386006", Map.of("fake", false), null, null);
var answers = new AskOnEntrySurvey("77386006", Map.of("fake", false), null, null, null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, null, null);
Expand All @@ -1042,7 +1043,8 @@ void convertToAoeObservation_pregnancyStatus_matchesJson() throws IOException {
@Test
void convertToAoeObservation_allAOE_matchesJson() throws IOException {
var answers =
new AskOnEntrySurvey("102874004", Map.of("fake", true), false, LocalDate.of(2023, 3, 4));
new AskOnEntrySurvey(
"102874004", Map.of("fake", true), false, LocalDate.of(2023, 3, 4), null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, false, false);
Expand All @@ -1059,7 +1061,7 @@ void convertToAoeObservation_allAOE_matchesJson() throws IOException {

@Test
void convertToAoeObservation_noAnswer_matchesJson() throws IOException {
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), false, null);
var answers = new AskOnEntrySurvey(null, Map.of("fake", false), false, null, null);
String testId = "fakeId";

var actual = fhirConverter.convertToAOEObservations(testId, answers, null, null);
Expand Down Expand Up @@ -1641,7 +1643,7 @@ void createFhirBundle_TestEvent_matchesJson() throws IOException {
"Adventurer of the cosmos");
var testOrder = new TestOrder(person, facility);
var answers =
new PatientAnswers(new AskOnEntrySurvey(null, Map.of("fake", false), false, null));
new PatientAnswers(new AskOnEntrySurvey(null, Map.of("fake", false), false, null, null));
testOrder.setAskOnEntrySurvey(answers);

var covidResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ void graphqlQuery_auditFailure_noDataReturned() {
args.put("symptoms", "{}");
args.put("noSymptoms", true);
String clientErrorMessage =
assertThrows(WebClientRequestException.class, () -> runQuery("update-time-of-test", args))
assertThrows(
WebClientRequestException.class,
() -> runQuery("update-time-of-test-questions", args))
.getMessage();
assertEquals(
"Request processing failed: header: Something went wrong; body: Please check for errors and try again",
Expand Down
Loading

0 comments on commit f955485

Please sign in to comment.