Skip to content

Commit

Permalink
refactor person creation to use builder in bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 committed Oct 17, 2023
1 parent 495713e commit 5004952
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateEmail;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateEthnicity;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateFlexibleDate;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateGenderIdentity;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validatePhoneNumber;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validatePhoneNumberType;
import static gov.cdc.usds.simplereport.validators.CsvValidatorUtils.validateRace;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class PatientUploadRow implements FileRow {
final ValueOrError residentCongregateSetting;
final ValueOrError role;
final ValueOrError email;
final ValueOrError genderIdentity;
final ValueOrError notes;

static final String FIRST_NAME = "first_name";
static final String LAST_NAME = "last_name";
Expand All @@ -58,6 +61,8 @@ public class PatientUploadRow implements FileRow {
static final String PHONE_NUMBER_TYPE = "phone_number_type";
static final String EMPLOYED_IN_HEALTHCARE = "employed_in_healthcare";
static final String RESIDENT_CONGREGATE_SETTING = "resident_congregate_setting";
static final String GENDER_IDENTITY = "gender_identity";
static final String ADDRESS_NOTES = "notes";

private static final List<String> requiredFields =
List.of(
Expand Down Expand Up @@ -99,6 +104,8 @@ public PatientUploadRow(Map<String, String> rawRow) {
getValue(rawRow, RESIDENT_CONGREGATE_SETTING, isRequired(RESIDENT_CONGREGATE_SETTING));
role = getValue(rawRow, "role", isRequired("role"));
email = getValue(rawRow, "email", isRequired("email"));
genderIdentity = getValue(rawRow, "genderIdentity", isRequired("genderIdentity"));
notes = getValue(rawRow, "notes", isRequired("notes"));
}

@Override
Expand All @@ -124,6 +131,7 @@ public List<FeedbackMessage> validateIndividualValues() {
errors.addAll(validateRace(race));
errors.addAll(validateBiologicalSex(biologicalSex));
errors.addAll(validateEthnicity(ethnicity));
errors.addAll(validateGenderIdentity(genderIdentity));

// housing, work, and role
errors.addAll(validateYesNoAnswer(residentCongregateSetting));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import lombok.Builder;
import lombok.Getter;
import org.hibernate.annotations.Type;

Expand Down Expand Up @@ -163,6 +164,56 @@ public Person(
this.notes = notes;
}

@Builder
public Person(
Organization organization,
Facility facility,
String lookupId,
String firstName,
String middleName,
String lastName,
String suffix,
LocalDate birthDate,
StreetAddress address,
String country,
PersonRole role,
List<String> emails,
String race,
String ethnicity,
List<String> tribalAffiliation,
String gender,
String genderIdentity,
Boolean residentCongregateSetting,
Boolean employedInHealthcare,
String preferredLanguage,
TestResultDeliveryPreference testResultDeliveryPreference,
String notes) {

this(
organization,
lookupId,
firstName,
middleName,
lastName,
suffix,
birthDate,
address,
country,
role,
emails,
race,
ethnicity,
tribalAffiliation,
gender,
genderIdentity,
residentCongregateSetting,
employedInHealthcare,
preferredLanguage,
testResultDeliveryPreference,
notes);
this.facility = facility;
}

public Person(
Organization organization,
Facility facility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,34 @@ public CompletableFuture<Set<Person>> savePatients(byte[] content, UUID facility

// create new person with current organization, then add to new patients list
Person newPatient =
new Person(
currentOrganization,
assignedFacility.orElse(null),
null, // lookupid
extractedData.getFirstName().getValue(),
extractedData.getMiddleName().getValue(),
extractedData.getLastName().getValue(),
extractedData.getSuffix().getValue(),
parseUserShortDate(extractedData.getDateOfBirth().getValue()),
address,
country,
parsePersonRole(extractedData.getRole().getValue(), false),
extractedData.getEmail().getValue() == null
? Collections.emptyList()
: List.of(extractedData.getEmail().getValue()),
convertRaceToDatabaseValue(extractedData.getRace().getValue()),
convertEthnicityToDatabaseValue(extractedData.getEthnicity().getValue()),
null, // tribalAffiliation
convertSexToDatabaseValue(extractedData.getBiologicalSex().getValue()),
parseYesNoUnk(extractedData.getResidentCongregateSetting().getValue()),
parseYesNoUnk(extractedData.getEmployedInHealthcare().getValue()),
null, // preferredLanguage
null // testResultDeliveryPreference
);
Person.builder()
.organization(currentOrganization)
.facility(assignedFacility.orElse(null))
.birthDate(parseUserShortDate(extractedData.getDateOfBirth().getValue()))
.address(address)
.country(country)
.role(parsePersonRole(extractedData.getRole().getValue(), false))
.emails(
extractedData.getEmail().getValue() == null
? Collections.emptyList()
: List.of(extractedData.getEmail().getValue()))
.race(convertRaceToDatabaseValue(extractedData.getRace().getValue()))
.ethnicity(convertEthnicityToDatabaseValue(extractedData.getEthnicity().getValue()))
.gender(convertSexToDatabaseValue(extractedData.getBiologicalSex().getValue()))
.genderIdentity(extractedData.getGenderIdentity().getValue())
.residentCongregateSetting(
parseYesNoUnk(extractedData.getResidentCongregateSetting().getValue()))
.employedInHealthcare(
parseYesNoUnk(extractedData.getEmployedInHealthcare().getValue()))
.firstName(extractedData.getFirstName().getValue())
.middleName(extractedData.getMiddleName().getValue())
.lastName(extractedData.getLastName().getValue())
.suffix(extractedData.getSuffix().getValue())
.lookupId(null)
.tribalAffiliation(null)
.preferredLanguage(null)
.testResultDeliveryPreference(null)
.build();

if (!allPatients.contains(newPatient)) {
// collect phone numbers and associate them with the patient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public class CsvValidatorUtils {
"u", UNKNOWN_LITERAL,
"a", "ambiguous",
"n", "not applicable");

private static final Set<String> GENDER_IDENTITY_VALUES =
Set.of("female", "male", "transwoman", "transman", "nonbinary", "other", "refused");
private static final Set<String> ETHNICITY_VALUES =
Set.of(
HISPANIC_CODE, HISPANIC_LITERAL,
Expand Down Expand Up @@ -300,6 +303,10 @@ public static List<FeedbackMessage> validateBiologicalSex(ValueOrError input) {
return validateInSet(input, GENDER_VALUES);
}

public static List<FeedbackMessage> validateGenderIdentity(ValueOrError input) {
return validateInSet(input, GENDER_IDENTITY_VALUES);
}

public static List<FeedbackMessage> validateState(ValueOrError input) {
return validateInSet(input, VALID_STATE_CODES);
}
Expand Down

0 comments on commit 5004952

Please sign in to comment.