|
|
@ -61,7 +61,6 @@ public class ShelterResucueService { |
|
|
this.jdbcShelterRescueTemplate = new JdbcTemplate(ShelterRescueataSource); |
|
|
this.jdbcShelterRescueTemplate = new JdbcTemplate(ShelterRescueataSource); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getSurveyQuestions(Integer cid) { |
|
|
public List<Map<String, Object>> getSurveyQuestions(Integer cid) { |
|
|
|
|
|
|
|
|
String childSql = "SELECT DISTINCT child_qid FROM shelter_resuce_question_mapping " + |
|
|
String childSql = "SELECT DISTINCT child_qid FROM shelter_resuce_question_mapping " + |
|
|
@ -362,7 +361,7 @@ public class ShelterResucueService { |
|
|
System.out.println(" resuceDesignation: " + resuceDesignation); |
|
|
System.out.println(" resuceDesignation: " + resuceDesignation); |
|
|
System.out.println(" hospitalName: " + hospitalName); |
|
|
System.out.println(" hospitalName: " + hospitalName); |
|
|
|
|
|
|
|
|
//String address = params.get("address"); ) |
|
|
|
|
|
|
|
|
// String address = params.get("address"); ) |
|
|
// System.out.println(" surveyId: " + surveyId); |
|
|
// System.out.println(" surveyId: " + surveyId); |
|
|
// System.out.println(" cid: " + cid); |
|
|
// System.out.println(" cid: " + cid); |
|
|
// System.out.println(" cby: " + cby); |
|
|
// System.out.println(" cby: " + cby); |
|
|
@ -428,9 +427,10 @@ public class ShelterResucueService { |
|
|
// first (like in child_survey) |
|
|
// first (like in child_survey) |
|
|
if (cid != null && cid.equals("1") && (zone != null || resolvedLat != null || resolvedLng != null)) { |
|
|
if (cid != null && cid.equals("1") && (zone != null || resolvedLat != null || resolvedLng != null)) { |
|
|
try { |
|
|
try { |
|
|
// String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + |
|
|
|
|
|
// "(loginId, zone, ward, latitude, longitude, shelter_id, is_active, is_delete, cdate) " + |
|
|
|
|
|
// "VALUES (?, ?, ?, ?, ?, ?, 1, 0, NOW())"; |
|
|
|
|
|
|
|
|
// String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + |
|
|
|
|
|
// "(loginId, zone, ward, latitude, longitude, shelter_id, is_active, is_delete, |
|
|
|
|
|
// cdate) " + |
|
|
|
|
|
// "VALUES (?, ?, ?, ?, ?, ?, 1, 0, NOW())"; |
|
|
|
|
|
|
|
|
String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + |
|
|
String logindetailsSql = "INSERT INTO surveyor_location_resuce_details " + |
|
|
"(loginId, zone, ward, latitude, longitude, shelter_id, " + |
|
|
"(loginId, zone, ward, latitude, longitude, shelter_id, " + |
|
|
@ -480,7 +480,7 @@ public class ShelterResucueService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//to save family members details |
|
|
|
|
|
|
|
|
// to save family members details |
|
|
// Detect and save family members details if passed as JSON string |
|
|
// Detect and save family members details if passed as JSON string |
|
|
String familyMembersJson = params.get("family_members"); |
|
|
String familyMembersJson = params.get("family_members"); |
|
|
if (familyMembersJson == null) { |
|
|
if (familyMembersJson == null) { |
|
|
@ -493,17 +493,18 @@ public class ShelterResucueService { |
|
|
// We will keep a list of keys that were parsed as family members JSON to skip |
|
|
// We will keep a list of keys that were parsed as family members JSON to skip |
|
|
// them in the main q-param loop |
|
|
// them in the main q-param loop |
|
|
List<String> parsedJsonKeys = new ArrayList<>(); |
|
|
List<String> parsedJsonKeys = new ArrayList<>(); |
|
|
// if (familyMembersJson != null && !familyMembersJson.trim().isEmpty() |
|
|
|
|
|
// && familyMembersJson.trim().startsWith("[")) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// List<Map<String, Object>> familyList = parseFamilyMembersJson(familyMembersJson); |
|
|
|
|
|
// if (familyList != null && !familyList.isEmpty()) { |
|
|
|
|
|
// saveFamilyMembers(familyList, surveyId, cby); |
|
|
|
|
|
// } |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
// if (familyMembersJson != null && !familyMembersJson.trim().isEmpty() |
|
|
|
|
|
// && familyMembersJson.trim().startsWith("[")) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// List<Map<String, Object>> familyList = |
|
|
|
|
|
// parseFamilyMembersJson(familyMembersJson); |
|
|
|
|
|
// if (familyList != null && !familyList.isEmpty()) { |
|
|
|
|
|
// saveFamilyMembers(familyList, surveyId, cby); |
|
|
|
|
|
// } |
|
|
|
|
|
// } catch (Exception e) { |
|
|
|
|
|
// e.printStackTrace(); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
Map<String, Map<Integer, Map<String, Object>>> structuredFamilyMap = new HashMap<>(); |
|
|
Map<String, Map<Integer, Map<String, Object>>> structuredFamilyMap = new HashMap<>(); |
|
|
java.util.regex.Pattern structPattern = java.util.regex.Pattern |
|
|
java.util.regex.Pattern structPattern = java.util.regex.Pattern |
|
|
@ -572,14 +573,10 @@ public class ShelterResucueService { |
|
|
+ |
|
|
+ |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String insertSql = "INSERT INTO shelter_resuce_response (qid, answer, others_answer, survey_id, cid, cby, parent_answer_id, cdate, isactive, isdelete) " |
|
|
String insertSql = "INSERT INTO shelter_resuce_response (qid, answer, others_answer, survey_id, cid, cby, parent_answer_id, cdate, isactive, isdelete) " |
|
|
+ |
|
|
+ |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; |
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 1, 0)"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String qSql = "SELECT qid, question_type, field_name, q_english FROM shelter_resuce_questions_master " |
|
|
String qSql = "SELECT qid, question_type, field_name, q_english FROM shelter_resuce_questions_master " |
|
|
+ "WHERE cid = ? AND (isactive = 1 AND isdelete = 0 OR (cid = '1' AND field_name IN ('q2', 'q78', 'q11', 'q8', 'q9', 'q10', 'q77')))"; |
|
|
+ "WHERE cid = ? AND (isactive = 1 AND isdelete = 0 OR (cid = '1' AND field_name IN ('q2', 'q78', 'q11', 'q8', 'q9', 'q10', 'q77')))"; |
|
|
List<Map<String, Object>> questions = jdbcShelterRescueTemplate.queryForList(qSql, cid); |
|
|
List<Map<String, Object>> questions = jdbcShelterRescueTemplate.queryForList(qSql, cid); |
|
|
@ -772,7 +769,7 @@ public class ShelterResucueService { |
|
|
|
|
|
|
|
|
if (isNotWilling) { |
|
|
if (isNotWilling) { |
|
|
jdbcShelterRescueTemplate.update(insertparticipateSql, qid, answer, othersAnswer, surveyId, |
|
|
jdbcShelterRescueTemplate.update(insertparticipateSql, qid, answer, othersAnswer, surveyId, |
|
|
cid, cby,parentAnswerId); |
|
|
|
|
|
|
|
|
cid, cby, parentAnswerId); |
|
|
|
|
|
|
|
|
// System.out.println("--- DB SAVE (Participate) --- QID: " + qid + " | |
|
|
// System.out.println("--- DB SAVE (Participate) --- QID: " + qid + " | |
|
|
// FieldName: " + fieldName + " | Answer: " + answer + " | OthersAnswer: " + |
|
|
// FieldName: " + fieldName + " | Answer: " + answer + " | OthersAnswer: " + |
|
|
@ -1098,7 +1095,6 @@ public class ShelterResucueService { |
|
|
return resultList; |
|
|
return resultList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> parseFamilyMembersJson(String jsonStr) { |
|
|
private List<Map<String, Object>> parseFamilyMembersJson(String jsonStr) { |
|
|
if (jsonStr == null || jsonStr.trim().isEmpty()) { |
|
|
if (jsonStr == null || jsonStr.trim().isEmpty()) { |
|
|
return new ArrayList<>(); |
|
|
return new ArrayList<>(); |
|
|
@ -1156,7 +1152,6 @@ public class ShelterResucueService { |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveFamilyMembers(List<Map<String, Object>> familyList, String surveyId, String cby) { |
|
|
private void saveFamilyMembers(List<Map<String, Object>> familyList, String surveyId, String cby) { |
|
|
if (familyList == null || familyList.isEmpty()) { |
|
|
if (familyList == null || familyList.isEmpty()) { |
|
|
return; |
|
|
return; |
|
|
@ -1202,14 +1197,13 @@ public class ShelterResucueService { |
|
|
qid = 8; |
|
|
qid = 8; |
|
|
} else if ("gender".equals(cleanKey)) { |
|
|
} else if ("gender".equals(cleanKey)) { |
|
|
qid = 9; |
|
|
qid = 9; |
|
|
} |
|
|
|
|
|
else if ("remark".equals(cleanKey)) { |
|
|
|
|
|
|
|
|
} else if ("remark".equals(cleanKey)) { |
|
|
qid = 10; |
|
|
qid = 10; |
|
|
|
|
|
} else if ("resucelocaton".equals(cleanKey)) { |
|
|
|
|
|
qid = 11; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback: If still null, try resolving by field_name or matching q_english |
|
|
// Fallback: If still null, try resolving by field_name or matching q_english |
|
|
// (case-insensitive) from DB without active/delete constraint |
|
|
// (case-insensitive) from DB without active/delete constraint |
|
|
if (qid == null) { |
|
|
if (qid == null) { |
|
|
@ -1251,20 +1245,20 @@ public class ShelterResucueService { |
|
|
parentAnswerId = 2; |
|
|
parentAnswerId = 2; |
|
|
} else if (qid == 9) { |
|
|
} else if (qid == 9) { |
|
|
parentAnswerId = 3; |
|
|
parentAnswerId = 3; |
|
|
} |
|
|
|
|
|
else if (qid == 10) { |
|
|
|
|
|
|
|
|
} else if (qid == 10) { |
|
|
parentAnswerId = 4; |
|
|
parentAnswerId = 4; |
|
|
|
|
|
} else if (qid == 11) { |
|
|
|
|
|
parentAnswerId = 5; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback: If still null, try resolving from mapping table (without |
|
|
// Fallback: If still null, try resolving from mapping table (without |
|
|
// active/delete constraint) |
|
|
// active/delete constraint) |
|
|
if (parentAnswerId == null) { |
|
|
if (parentAnswerId == null) { |
|
|
try { |
|
|
try { |
|
|
String parentAidSql = "SELECT parent_aid FROM rag_picker_question_mapping WHERE child_qid = ? LIMIT 1"; |
|
|
String parentAidSql = "SELECT parent_aid FROM rag_picker_question_mapping WHERE child_qid = ? LIMIT 1"; |
|
|
List<Integer> list = jdbcShelterRescueTemplate.queryForList(parentAidSql, Integer.class, qid); |
|
|
|
|
|
|
|
|
List<Integer> list = jdbcShelterRescueTemplate.queryForList(parentAidSql, Integer.class, |
|
|
|
|
|
qid); |
|
|
if (!list.isEmpty()) { |
|
|
if (!list.isEmpty()) { |
|
|
parentAnswerId = list.get(0); |
|
|
parentAnswerId = list.get(0); |
|
|
} |
|
|
} |
|
|
@ -1290,6 +1284,4 @@ public class ShelterResucueService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |