|
|
|
@ -9,6 +9,7 @@ import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.security.SecureRandom; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
@ -118,7 +119,7 @@ public class NightShelterInspectionService { |
|
|
|
return finalList; |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String, Object> buildQuestionWithOptions(Map<String, Object> q) { |
|
|
|
private Map<String, Object> buildQuestionWithOptions1(Map<String, Object> q) { |
|
|
|
|
|
|
|
Integer qid = (Integer) q.get("qid"); |
|
|
|
String masterTable = (String) safe(q.get("master_table_name")); |
|
|
|
@ -185,6 +186,191 @@ public class NightShelterInspectionService { |
|
|
|
|
|
|
|
return questionMap; |
|
|
|
} |
|
|
|
private Map<String, Object> buildQuestionWithOptions(Map<String, Object> q) { |
|
|
|
|
|
|
|
Integer qid = (Integer) q.get("qid"); |
|
|
|
String masterTable = (String) safe(q.get("master_table_name")); |
|
|
|
|
|
|
|
// Maintain order |
|
|
|
Map<String, Object> questionMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
questionMap.put("qid", q.get("qid")); |
|
|
|
questionMap.put("q_english", q.get("q_english")); |
|
|
|
questionMap.put("q_tamil", safe(q.get("q_tamil"))); |
|
|
|
questionMap.put("field_name", q.get("field_name")); |
|
|
|
questionMap.put("cdate", q.get("cdate")); |
|
|
|
questionMap.put("question_type", q.get("question_type")); |
|
|
|
questionMap.put("isactive", q.get("isactive")); |
|
|
|
questionMap.put("isdelete", q.get("isdelete")); |
|
|
|
questionMap.put("orderby", q.get("orderby")); |
|
|
|
questionMap.put("is_mandatory", q.get("is_mandatory")); |
|
|
|
questionMap.put("is_dropdown", q.get("is_dropdown")); |
|
|
|
questionMap.put("flag", q.get("flag")); |
|
|
|
questionMap.put("master_table_name", masterTable); |
|
|
|
|
|
|
|
List<Map<String, Object>> options = new ArrayList<>(); |
|
|
|
|
|
|
|
if (masterTable != null && !masterTable.isEmpty()) { |
|
|
|
|
|
|
|
if (masterTable.equalsIgnoreCase("state_master") |
|
|
|
|| masterTable.equalsIgnoreCase("district_master")) { |
|
|
|
|
|
|
|
options = new ArrayList<>(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Existing master options |
|
|
|
options = getOptionsFromMaster(masterTable, qid); |
|
|
|
|
|
|
|
// ===================================================== |
|
|
|
// NOT APPLICABLE LOGIC - ONLY FOR document_master |
|
|
|
// ===================================================== |
|
|
|
|
|
|
|
if (masterTable.equalsIgnoreCase("document_master")) { |
|
|
|
|
|
|
|
// Remove Not applicable from the normal master options |
|
|
|
// because we will add it conditionally below. |
|
|
|
options.removeIf(option -> |
|
|
|
"Not applicable".equalsIgnoreCase( |
|
|
|
String.valueOf(option.get("english_name")) |
|
|
|
) |
|
|
|
); |
|
|
|
|
|
|
|
String notApplicableSql = |
|
|
|
"SELECT id AS option_id, " + |
|
|
|
" english_name, " + |
|
|
|
" notapplicable_qid " + |
|
|
|
"FROM gcc_night_shelter_inspection.document_master " + |
|
|
|
"WHERE LOWER(english_name) = 'not applicable' " + |
|
|
|
"AND isactive = 1 " + |
|
|
|
"AND isdelete = 0"; |
|
|
|
|
|
|
|
List<Map<String, Object>> notApplicableOptions = |
|
|
|
jdbcNightShelterInspectionTemplate.queryForList( |
|
|
|
notApplicableSql |
|
|
|
); |
|
|
|
|
|
|
|
for (Map<String, Object> opt : notApplicableOptions) { |
|
|
|
|
|
|
|
Object qidObj = opt.get("notapplicable_qid"); |
|
|
|
|
|
|
|
if (qidObj == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
String notApplicableQids = qidObj.toString().trim(); |
|
|
|
|
|
|
|
boolean shouldShow = false; |
|
|
|
|
|
|
|
// 0 = show for ALL questions |
|
|
|
if ("0".equals(notApplicableQids)) { |
|
|
|
|
|
|
|
shouldShow = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Example: |
|
|
|
// 29,30,31,32,34,40 |
|
|
|
shouldShow = Arrays.stream( |
|
|
|
notApplicableQids.split(",") |
|
|
|
) |
|
|
|
.map(String::trim) |
|
|
|
.anyMatch(id -> |
|
|
|
id.equals(String.valueOf(qid)) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (shouldShow) { |
|
|
|
|
|
|
|
Map<String, Object> optionMap = |
|
|
|
new LinkedHashMap<>(); |
|
|
|
|
|
|
|
optionMap.put( |
|
|
|
"option_id", |
|
|
|
opt.get("option_id") |
|
|
|
); |
|
|
|
|
|
|
|
optionMap.put( |
|
|
|
"english_name", |
|
|
|
opt.get("english_name") |
|
|
|
); |
|
|
|
|
|
|
|
optionMap.put("tamil_name", ""); |
|
|
|
optionMap.put("orderby", 999); |
|
|
|
optionMap.put("is_mandatory", 0); |
|
|
|
optionMap.put("is_others", false); |
|
|
|
optionMap.put("text", false); |
|
|
|
optionMap.put( |
|
|
|
"child_questions", |
|
|
|
new ArrayList<>() |
|
|
|
); |
|
|
|
|
|
|
|
options.add(optionMap); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
String optSql = |
|
|
|
"SELECT id AS option_id, answer AS english_name, " + |
|
|
|
"orderby, is_mandatory " + |
|
|
|
"FROM night_shelter_inspection_answer_master " + |
|
|
|
"WHERE qid=? " + |
|
|
|
"AND isactive=1 " + |
|
|
|
"AND isdelete=0 " + |
|
|
|
"ORDER BY orderby"; |
|
|
|
|
|
|
|
List<Map<String, Object>> dbOptions = |
|
|
|
jdbcNightShelterInspectionTemplate.queryForList( |
|
|
|
optSql, |
|
|
|
qid |
|
|
|
); |
|
|
|
|
|
|
|
for (Map<String, Object> opt : dbOptions) { |
|
|
|
|
|
|
|
Map<String, Object> optionMap = |
|
|
|
new LinkedHashMap<>(); |
|
|
|
|
|
|
|
String englishName = |
|
|
|
(String) opt.get("english_name"); |
|
|
|
|
|
|
|
optionMap.put("option_id", opt.get("option_id")); |
|
|
|
optionMap.put("english_name", englishName); |
|
|
|
optionMap.put("tamil_name", ""); |
|
|
|
optionMap.put("orderby", opt.get("orderby")); |
|
|
|
optionMap.put( |
|
|
|
"is_mandatory", |
|
|
|
opt.get("is_mandatory") |
|
|
|
); |
|
|
|
|
|
|
|
boolean isOthers = |
|
|
|
englishName != null |
|
|
|
&& englishName.equalsIgnoreCase("Others"); |
|
|
|
|
|
|
|
optionMap.put("is_others", isOthers); |
|
|
|
optionMap.put("text", isOthers); |
|
|
|
|
|
|
|
Integer aid = |
|
|
|
(Integer) opt.get("option_id"); |
|
|
|
|
|
|
|
List<Map<String, Object>> childQuestions = |
|
|
|
getChildQuestionsRecursive(aid); |
|
|
|
|
|
|
|
optionMap.put( |
|
|
|
"child_questions", |
|
|
|
childQuestions |
|
|
|
); |
|
|
|
|
|
|
|
options.add(optionMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
questionMap.put("options", options); |
|
|
|
|
|
|
|
return questionMap; |
|
|
|
} |
|
|
|
|
|
|
|
private List<Map<String, Object>> getChildQuestionsRecursive(Integer parentAid) { |
|
|
|
|
|
|
|
|