Skip to content

Commit

Permalink
#96 - renamed to fix spelling and clarifying the source of data
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 3, 2023
1 parent c7ad838 commit d51f8e1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.avni_integration_service.lahi.config;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

import static java.util.Map.entry;

public interface LahiMappingDbConstants {
String MAPPINGTYPE_OBS = "Observations";
String MAPPINGGROUP_STUDENT = "Student";
String MAPPING_TYPE_OBS = "Observations";
String MAPPING_GROUP_STUDENT = "Student";

String CONTACT_PHONE_NUMBER = "Student contact number";
String ALTERNATE_PHONE_NUMBER = "Alternate (Whatsapp number)";

//todo create constants for all string literals below
Map<String,Object> DEFAUL_STUDENT_OBSVALUE_MAP = Map.ofEntries(
Map<String,Object> DEFAULT_STUDENT_OBS_VALUE_MAP = Map.ofEntries(
entry("Does student give permission to LAHI to Send Whatsapp/SMS/Call for any career opportunities?","Yes"),
entry("Career options you are interested in", Arrays.asList("Other")),
entry("Career options you are interested in", Collections.singletonList("Other")),
entry("User","LAHI Program Team"),
entry("Student/Trainee Type","Regular"),
entry("Registration Source","Glific"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.Map;

import static org.avni_integration_service.lahi.domain.StudentConstants.FLOWRESULT_ID;
import static org.avni_integration_service.lahi.domain.LahiStudentConstants.FLOWRESULT_ID;

public abstract class LahiEntity {
protected Map<String, Object> response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.log4j.Logger;
import org.avni_integration_service.avni.domain.Subject;
import org.avni_integration_service.lahi.util.DateTimeUtil;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@JsonIgnoreProperties(ignoreUnknown = true)
public class LahiStudent extends LahiEntity implements StudentConstants {
public class LahiStudent extends LahiEntity implements LahiStudentConstants {
private static final Logger logger = Logger.getLogger(LahiStudent.class);
private static final List<String> Core_Fields = Arrays.asList(FIRST_NAME,LAST_NAME,DATE_OF_BIRTH, DATE_OF_REGISTRATION,GENDER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Arrays;
import java.util.List;

public interface StudentConstants {
public interface LahiStudentConstants {
String FIRST_NAME = "avni_first_name";
String LAST_NAME = "avni_last_name";
String DATE_OF_BIRTH = "avni_date_of_birth";
Expand Down Expand Up @@ -57,7 +57,7 @@ public interface StudentConstants {
FLOWRESULT_ID
);

List<String> MandatoryField =
List<String> MandatoryFields =
Arrays.asList(
FIRST_NAME,
LAST_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class StudentValidator {
private static final Logger logger = Logger.getLogger(BigQueryClient.class);

public void validateMandatoryField(Map<String, Object> map) {
long count = StudentConstants.MandatoryField.stream().filter(field -> {
long count = LahiStudentConstants.MandatoryFields.stream().filter(field -> {
if (map.getOrDefault(field, null) == null) {
logger.error(String.format("%s missing for id:%s", field, map.get("id")));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.Date;

import static org.avni_integration_service.lahi.domain.StudentConstants.FLOW_RESULT_UPDATED_AT;
import static org.avni_integration_service.lahi.domain.LahiStudentConstants.FLOW_RESULT_UPDATED_AT;
import static org.avni_integration_service.lahi.service.LahiStudentService.ENTITYTYPE;

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import static org.avni_integration_service.lahi.domain.StudentConstants.ResultFieldList;
import static org.avni_integration_service.lahi.domain.LahiStudentConstants.ResultFieldList;

@Service
public class LahiStudentService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.avni_integration_service.lahi.config.LahiMappingDbConstants;
import org.avni_integration_service.lahi.domain.LahiEntity;
import org.avni_integration_service.lahi.domain.LahiStudent;
import org.avni_integration_service.lahi.domain.StudentConstants;
import org.avni_integration_service.lahi.domain.LahiStudentConstants;
import org.avni_integration_service.lahi.util.DateTimeUtil;
import org.avni_integration_service.util.ObsDataType;
import org.springframework.stereotype.Service;
Expand All @@ -20,7 +20,7 @@
import java.util.Map;

@Service
public class StudentMapper implements StudentConstants {
public class StudentMapper implements LahiStudentConstants {
private static final Logger logger = Logger.getLogger(StudentMapper.class);
private final MappingMetaDataRepository mappingMetaDataRepository;

Expand All @@ -30,9 +30,9 @@ public StudentMapper(MappingMetaDataRepository mappingMetaDataRepository) {

public Subject mapToSubject(LahiStudent lahiStudent) {
Subject subject = this.subjectWithoutObservations(lahiStudent.getResponse());
this.populateObservations(subject, lahiStudent, LahiMappingDbConstants.MAPPINGGROUP_STUDENT);
this.populateObservations(subject, lahiStudent, LahiMappingDbConstants.MAPPING_GROUP_STUDENT);
Map<String, Object> observations = subject.getObservations();
LahiMappingDbConstants.DEFAUL_STUDENT_OBSVALUE_MAP.forEach(observations::put);
LahiMappingDbConstants.DEFAULT_STUDENT_OBS_VALUE_MAP.forEach(observations::put);
setOtherAddress(subject, lahiStudent);
setPhoneNumber(subject, lahiStudent);
return subject;
Expand All @@ -41,7 +41,7 @@ public Subject mapToSubject(LahiStudent lahiStudent) {
private void populateObservations(ObservationHolder observationHolder, LahiEntity lahiEntity, String mappingGroup) {
List<String> observationFields = lahiEntity.getObservationFields();
for (String obsField : observationFields) {
MappingMetaData mapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPINGTYPE_OBS, obsField, 5);
MappingMetaData mapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPING_TYPE_OBS, obsField, 5);
if(mapping == null) {
logger.error("Mapping entry not found for observation field: " + obsField);
continue;
Expand All @@ -50,7 +50,7 @@ private void populateObservations(ObservationHolder observationHolder, LahiEntit
if (dataTypeHint == null)
observationHolder.addObservation(mapping.getAvniValue(), lahiEntity.getValue(obsField));
else if (dataTypeHint == ObsDataType.Coded && lahiEntity.getValue(obsField) != null) {
MappingMetaData answerMapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPINGTYPE_OBS, lahiEntity.getValue(obsField).toString(), 5);
MappingMetaData answerMapping = mappingMetaDataRepository.getAvniMappingIfPresent(mappingGroup, LahiMappingDbConstants.MAPPING_TYPE_OBS, lahiEntity.getValue(obsField).toString(), 5);
if(answerMapping == null) {
String errorMessage = "Answer Mapping entry not found for coded concept answer field: " + obsField;
logger.error(errorMessage);
Expand All @@ -65,36 +65,36 @@ private void setOtherAddress(Subject subject, LahiStudent student) {
Map<String, Object> subjectObservations = subject.getObservations();
Map<String, Object> studentResponse = student.getResponse();
StringBuilder stringBuilder = new StringBuilder();
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.STATE, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.OTHER_STATE, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.DISTRICT, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.CITY_NAME, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(StudentConstants.SCHOOL, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.STATE, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.OTHER_STATE, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.DISTRICT, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.CITY_NAME, ""));
setAddressString(stringBuilder, (String) studentResponse.getOrDefault(LahiStudentConstants.SCHOOL, ""));
if (stringBuilder.length() > 0) {
subjectObservations.put("Other School name", stringBuilder.toString());
}
}

private void setAddressString(StringBuilder stringBuilder, String string) {
if (string != null && !string.equals("")) {
stringBuilder.append(string + " ");
if (StringUtils.hasLength(string)) {
stringBuilder.append(string).append(" ");
}
}

private void setPhoneNumber(Subject subject, LahiStudent student) {
Map<String, Object> subjectObservations = subject.getObservations();
String contactPhoneNumber = null;
if (student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER) != null
&& student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER).toString().length() == 12) {
contactPhoneNumber = ((String) student.getValue(StudentConstants.STUDENT_CONTACT_NUMBER)).substring(2);
Object contactNumber = student.getValue(LahiStudentConstants.STUDENT_CONTACT_NUMBER);
if (contactNumber != null && contactNumber.toString().length() == 12) {
contactPhoneNumber = ((String) contactNumber).substring(2);
subjectObservations.put(LahiMappingDbConstants.CONTACT_PHONE_NUMBER, contactPhoneNumber);
}
setAlternatePhoneNumber(student, subjectObservations, contactPhoneNumber);
}

private void setAlternatePhoneNumber(LahiStudent student, Map<String, Object> subjectObservations, String contactPhoneNumber) {
Long alternatePhoneNumber;
String alternateNumber = (String) student.getValue(StudentConstants.ALTERNATE_NUMBER);
String alternateNumber = (String) student.getValue(LahiStudentConstants.ALTERNATE_NUMBER);
if (StringUtils.hasText(alternateNumber) && alternateNumber.length() == 12) {
alternateNumber = alternateNumber.substring(2);
}
Expand Down

0 comments on commit d51f8e1

Please sign in to comment.