Skip to content

Commit

Permalink
#546 | Add geolocation points to longitudinal export
Browse files Browse the repository at this point in the history
(cherry picked from commit fd13bb1)
  • Loading branch information
1t5j0y committed Jul 3, 2023
1 parent 8240762 commit 0fb4e82
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private void addEncounterHeaders(Long maxVisitCount, StringBuilder headers) {
headers.append(",").append(prefix).append(".earliest_visit_date_time");
headers.append(",").append(prefix).append(".max_visit_date_time");
headers.append(",").append(prefix).append(".encounter_date_time");
headers.append(",").append(prefix).append(".encounter_location");
headers.append(",").append(prefix).append(".cancel_location");
appendObsColumns(headers, prefix, programUUID != null ? programEncounterMap : encounterMap);
headers.append(",").append(prefix).append(".cancel_date_time");
appendObsColumns(headers, prefix, programUUID != null ? programEncounterCancelMap : encounterCancelMap);
Expand All @@ -161,8 +163,10 @@ private void addEnrolmentHeaders(StringBuilder headers) {
headers.append(",").append("enl.id");
headers.append(",").append("enl.uuid");
headers.append(",").append("enl.enrolment_date_time");
headers.append(",").append("enl.program_enrolment_location");
appendObsColumns(headers, "enl", enrolmentMap);
headers.append(",").append("enl.program_exit_date_time");
headers.append(",").append("enl.program_exit_location");
appendObsColumns(headers, "enl_exit", exitEnrolmentMap);
addAuditColumns(headers, "enl");
addVoidedColumnIfRequired(headers, "enl");
Expand All @@ -177,6 +181,7 @@ private void addRegistrationHeaders(StringBuilder headers, SubjectType subjectTy
headers.append(",").append("ind.last_name");
headers.append(",").append("ind.date_of_birth");
headers.append(",").append("ind.registration_date");
headers.append(",").append("ind.registration_location");
headers.append(",").append("ind.gender");
addAddressLevelColumns(headers);
if(subjectType.isGroup()) {
Expand Down Expand Up @@ -236,6 +241,7 @@ public Object[] extract(ExportItemRow exportItemRow) {
row.add(QuotedStringValue(individual.getLastName()));
row.add(individual.getDateOfBirth());
row.add(individual.getRegistrationDate());
row.add(individual.getRegistrationLocation());
row.add(gender == null ? "" : gender.getName());
addAddressLevels(row, addressLevel);
if (subjectType.isGroup()) {
Expand Down Expand Up @@ -302,9 +308,11 @@ private void addProgramEnrolmentFields(ExportItemRow exportItemRow, List<Object>
row.add(programEnrolment.getId());
row.add(programEnrolment.getUuid());
row.add(getDateForTimeZone(programEnrolment.getEnrolmentDateTime()));
row.add(programEnrolment.getEnrolmentLocation());
row.addAll(getObs(programEnrolment.getObservations(), enrolmentMap));
//Program Exit
row.add(getDateForTimeZone(programEnrolment.getProgramExitDateTime()));
row.add(programEnrolment.getExitLocation());
row.addAll(getObs(programEnrolment.getProgramExitObservations(), exitEnrolmentMap));
addAuditFields(programEnrolment, row);
addVoidedFieldIfRequired(programEnrolment, row);
Expand All @@ -327,6 +335,8 @@ private <T extends AbstractEncounter> void addEncounter(List<Object> row, T enco
row.add(getDateForTimeZone(encounter.getEarliestVisitDateTime()));
row.add(getDateForTimeZone(encounter.getMaxVisitDateTime()));
row.add(getDateForTimeZone(encounter.getEncounterDateTime()));
row.add(encounter.getEncounterLocation());
row.add(encounter.getCancelLocation());
row.addAll(getObs(encounter.getObservations(), map));
row.add(getDateForTimeZone(encounter.getCancelDateTime()));
row.addAll(getObs(encounter.getCancelObservations(), cancelMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ExportV2ValidationHelper implements LongitudinalExportRequestFieldN
CREATED_DATE_TIME,
LAST_MODIFIED_BY,
LAST_MODIFIED_DATE_TIME,
REGISTRATION_LOCATION,
VOIDED);

private static List<String> validEnrolmentFields = Arrays.asList(
Expand All @@ -45,6 +46,8 @@ public class ExportV2ValidationHelper implements LongitudinalExportRequestFieldN
CREATED_DATE_TIME,
LAST_MODIFIED_BY,
LAST_MODIFIED_DATE_TIME,
ENROLMENT_LOCATION,
EXIT_LOCATION,
VOIDED);


Expand All @@ -60,6 +63,8 @@ public class ExportV2ValidationHelper implements LongitudinalExportRequestFieldN
CREATED_DATE_TIME,
LAST_MODIFIED_BY,
LAST_MODIFIED_DATE_TIME,
ENCOUNTER_LOCATION,
CANCEL_LOCATION,
VOIDED);

private void validateFields(List<String> errorList, String entityName, List<String> requestFields, List<String> allowedFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class HeaderCreator implements LongitudinalExportRequestFieldNameConstant
put(CREATED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_CREATED_DATE_TIME, Individual::getCreatedDateTime));
put(LAST_MODIFIED_BY, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_BY, (Individual individual) -> individual.getLastModifiedBy().getName()));
put(LAST_MODIFIED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_DATE_TIME, Individual::getLastModifiedDateTime));
put(REGISTRATION_LOCATION, new HeaderNameAndFunctionMapper<>(HEADER_NAME_REGISTRATION_LOCATION, Individual::getRegistrationLocation));
put(VOIDED, new HeaderNameAndFunctionMapper<>(HEADER_NAME_VOIDED, CHSEntity::isVoided));
}};

Expand All @@ -47,6 +48,8 @@ public class HeaderCreator implements LongitudinalExportRequestFieldNameConstant
put(CREATED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_CREATED_DATE_TIME, ProgramEnrolment::getCreatedDateTime));
put(LAST_MODIFIED_BY, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_BY, (ProgramEnrolment individual) -> individual.getLastModifiedBy().getName()));
put(LAST_MODIFIED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_DATE_TIME, ProgramEnrolment::getLastModifiedDateTime));
put(ENROLMENT_LOCATION, new HeaderNameAndFunctionMapper<>(HEADER_NAME_ENROLMENT_LOCATION, ProgramEnrolment::getEnrolmentLocation));
put(EXIT_LOCATION, new HeaderNameAndFunctionMapper<>(HEADER_NAME_EXIT_LOCATION, ProgramEnrolment::getExitLocation));
put(VOIDED, new HeaderNameAndFunctionMapper<>(HEADER_NAME_VOIDED, CHSEntity::isVoided));
}};

Expand All @@ -63,6 +66,8 @@ public class HeaderCreator implements LongitudinalExportRequestFieldNameConstant
put(CREATED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_CREATED_DATE_TIME, AbstractEncounter::getCreatedDateTime));
put(LAST_MODIFIED_BY, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_BY, (AbstractEncounter individual) -> individual.getLastModifiedBy().getName()));
put(LAST_MODIFIED_DATE_TIME, new HeaderNameAndFunctionMapper<>(HEADER_NAME_LAST_MODIFIED_DATE_TIME, AbstractEncounter::getLastModifiedDateTime));
put(ENCOUNTER_LOCATION, new HeaderNameAndFunctionMapper<>(HEADER_NAME_ENCOUNTER_LOCATION, AbstractEncounter::getEncounterLocation));
put(CANCEL_LOCATION, new HeaderNameAndFunctionMapper<>(HEADER_NAME_CANCEL_LOCATION, AbstractEncounter::getCancelLocation));
put(VOIDED, new HeaderNameAndFunctionMapper<>(HEADER_NAME_VOIDED, CHSEntity::isVoided));
}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public interface LongitudinalExportDBFieldNameConstants {
String HEADER_NAME_MAX_VISIT_DATE_TIME = "max_visit_date_time";
String HEADER_NAME_ENCOUNTER_DATE_TIME = "encounter_date_time";
String HEADER_NAME_CANCEL_DATE_TIME = "cancel_date_time";
String HEADER_NAME_REGISTRATION_LOCATION = "registration_location";
String HEADER_NAME_ENROLMENT_LOCATION = "enrolment_location";
String HEADER_NAME_EXIT_LOCATION = "exit_location";
String HEADER_NAME_ENCOUNTER_LOCATION = "encounter_location";
String HEADER_NAME_CANCEL_LOCATION = "cancel_location";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public interface LongitudinalExportRequestFieldNameConstants {
String MAX_VISIT_DATE_TIME = "maxVisitDateTime";
String ENCOUNTER_DATE_TIME = "encounterDateTime";
String CANCEL_DATE_TIME = "cancelDateTime";
String REGISTRATION_LOCATION = "registrationLocation";
String ENROLMENT_LOCATION = "enrolmentLocation";
String EXIT_LOCATION = "exitLocation";
String ENCOUNTER_LOCATION = "encounterLocation";
String CANCEL_LOCATION = "cancelLocation";

}
5 changes: 5 additions & 0 deletions avni-server-api/src/main/java/org/avni/server/geo/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public int hashCode() {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}

@Override
public String toString() {
return String.format("\"%f,%f\"", x, y);
}
}

0 comments on commit 0fb4e82

Please sign in to comment.