Skip to content

Commit

Permalink
ALS-6511: Minor fixes and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Aug 13, 2024
1 parent 93630c3 commit 37c739f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public void appendResults(List<String[]> entries) {
writer.writeEntity(entries);
}
/**
* A more compact method to append data to the temp file without making assumptions about the composition.
* @param entries
* Appending data to the writer that supports multiple values per patient/variable combination
*/
public void appendMultiValueResults(List<List<List<String>>> entries) {
writer.writeMultiValueEntity(entries);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ private boolean isSingularField(String field) {
return SINGULAR_FIELDS.contains(field);
}

/**
* Transforms our variable names to once that are valid avro fields. We replace invalid characters with underscores
* and add a leading underscore if the variable starts with a number
*/
protected String formatFieldName(String s) {
String formattedFieldName = s.replaceAll("\\W", "_");
if (Character.isDigit(formattedFieldName.charAt(0))) {
Expand Down Expand Up @@ -141,7 +145,11 @@ public void writeMultiValueEntity(Collection<List<List<String>>> entities) {
throw new IllegalArgumentException("Entity length much match the number of fields in this document");
}
GenericRecord patientData = new GenericData.Record(patientDataSchema);
String patientId = "";
for(int i = 0; i < fields.size(); i++) {
if ("patient_id".equals(fields.get(i))) {
patientId = (entity.get(i) != null && !entity.get(i).isEmpty()) ? entity.get(i).get(0) : "";
}
if (isSingularField(fields.get(i))) {
String entityValue = (entity.get(i) != null && !entity.get(i).isEmpty()) ? entity.get(i).get(0) : "";
patientData.put(fields.get(i), entityValue);
Expand All @@ -155,7 +163,7 @@ public void writeMultiValueEntity(Collection<List<List<String>>> entities) {
GenericRecord entityRecord = new GenericData.Record(entitySchema);
entityRecord.put("object", patientData);
entityRecord.put("name", "patientData");
entityRecord.put("id", "192035");
entityRecord.put("id", patientId);

try {
dataFileWriter.append(entityRecord);
Expand Down

0 comments on commit 37c739f

Please sign in to comment.