tango-app-api-trax 3.8.25 → 3.8.26-nike
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/controllers/download.controller.js +19 -19
- package/src/controllers/gallery.controller.js +92 -28
- package/src/controllers/handlebar-helper.js +1 -0
- package/src/controllers/internalTrax.controller.js +418 -172
- package/src/controllers/mobileTrax.controller.js +770 -168
- package/src/controllers/teaxFlag.controller.js +5 -5
- package/src/controllers/trax.controller.js +6 -2
- package/src/hbs/flag.hbs +248 -248
- package/src/hbs/login-otp.hbs +943 -943
- package/src/hbs/recurringFlag.hbs +250 -253
- package/src/hbs/template.hbs +6 -2
- package/src/hbs/visit-checklist.hbs +82 -38
- package/src/hbs/weeklyWrap.hbs +218 -218
- package/src/routes/mobileTrax.routes.js +1 -0
- package/src/utils/visitChecklistPdf.utils.js +6 -5
|
@@ -118,7 +118,7 @@ export async function startChecklist( req, res ) {
|
|
|
118
118
|
$and: [
|
|
119
119
|
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
120
120
|
{ userId: req.user._id },
|
|
121
|
-
{ date_string: requestData.date },
|
|
121
|
+
{ $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
|
|
122
122
|
],
|
|
123
123
|
},
|
|
124
124
|
} );
|
|
@@ -137,7 +137,9 @@ export async function startChecklist( req, res ) {
|
|
|
137
137
|
let updateQuery = {};
|
|
138
138
|
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
139
139
|
updateQuery.userId = req.user._id;
|
|
140
|
-
|
|
140
|
+
if ( getBeforeChecklist?.[0]?.date_string == dayjs().format( 'YYYY-MM-DD' ) ) {
|
|
141
|
+
updateQuery.date_string = requestData.date;
|
|
142
|
+
}
|
|
141
143
|
|
|
142
144
|
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
143
145
|
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
@@ -317,7 +319,7 @@ export async function startChecklist( req, res ) {
|
|
|
317
319
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
318
320
|
}
|
|
319
321
|
} catch ( e ) {
|
|
320
|
-
|
|
322
|
+
console.log( 'e =>', e );
|
|
321
323
|
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
322
324
|
return res.sendError( e, 500 );
|
|
323
325
|
}
|
|
@@ -467,7 +469,7 @@ export async function startTask( req, res ) {
|
|
|
467
469
|
} );
|
|
468
470
|
const getUpdatedTask = await processedTask.aggregate( findQuery );
|
|
469
471
|
|
|
470
|
-
|
|
472
|
+
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
471
473
|
if ( !( task.checkListFrom && task.checkListFrom == 'api' ) ) {
|
|
472
474
|
// const bucket = JSON.parse( process.env.BUCKET );
|
|
473
475
|
await Promise.all(
|
|
@@ -661,12 +663,12 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
|
|
|
661
663
|
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
662
664
|
if ( sectionQuestion.length ) {
|
|
663
665
|
if ( requestData.submittype == 'submit' ) {
|
|
664
|
-
if ( ( [ 'multipleImage', 'multiplechoicemultiple' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
|
|
666
|
+
if ( ( [ 'multipleImage', 'multiplechoicemultiple', 'image/video' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
|
|
665
667
|
if ( ( !sectionQuestion[0].linkType || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled ) ) && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
|
|
666
668
|
validationCount++;
|
|
667
669
|
}
|
|
668
670
|
} else {
|
|
669
|
-
if ( ( !
|
|
671
|
+
if ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) {
|
|
670
672
|
validationCount++;
|
|
671
673
|
}
|
|
672
674
|
}
|
|
@@ -1049,7 +1051,523 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1049
1051
|
}
|
|
1050
1052
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1051
1053
|
structure.redo = false;
|
|
1052
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1054
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1055
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1056
|
+
}
|
|
1057
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1058
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1059
|
+
};
|
|
1060
|
+
newArray.push( structure );
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
let sectionData = {
|
|
1066
|
+
'section_id': section.id,
|
|
1067
|
+
'sectionName': section.name,
|
|
1068
|
+
'questions': newArray,
|
|
1069
|
+
};
|
|
1070
|
+
sectionFormat.push( sectionData );
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
requestData.questionAnswers = sectionFormat;
|
|
1076
|
+
next();
|
|
1077
|
+
} catch ( error ) {
|
|
1078
|
+
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1079
|
+
return res.sendError( error, 500 );
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next ) {
|
|
1084
|
+
try {
|
|
1085
|
+
let requestData = req.body;
|
|
1086
|
+
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1087
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1088
|
+
let reqAnswers = requestData.questionAnswers;
|
|
1089
|
+
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1090
|
+
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1091
|
+
|
|
1092
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1093
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1094
|
+
requestData.submittype = 'draft';
|
|
1095
|
+
}
|
|
1096
|
+
reqAnswers.forEach( ( reqA ) => {
|
|
1097
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1098
|
+
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1099
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
} );
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1106
|
+
let sampleData = reqAnswers[0];
|
|
1107
|
+
CLQAnswers.forEach( ( section ) => {
|
|
1108
|
+
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1109
|
+
if ( requestSection.length ) {
|
|
1110
|
+
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1111
|
+
section.questions.forEach( ( question ) => {
|
|
1112
|
+
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1113
|
+
if ( !sectionQuestion.length ) {
|
|
1114
|
+
let data = { ...requestSection[0] };
|
|
1115
|
+
data.answerType = question.answerType;
|
|
1116
|
+
data.qno = question.qno;
|
|
1117
|
+
data.uniqueqno = question.uniqueqno;
|
|
1118
|
+
data.uniqueqid = question.uniqueqid;
|
|
1119
|
+
data.qname = question.qname;
|
|
1120
|
+
data.oldQname = question?.oldQname || question.qname;
|
|
1121
|
+
data.answer = 'null';
|
|
1122
|
+
data.remarks = '';
|
|
1123
|
+
data.validationAnswer = '';
|
|
1124
|
+
data.Multianswer = [];
|
|
1125
|
+
data.linkType = question.linkType;
|
|
1126
|
+
data.linkquestionenabled = question.linkType;
|
|
1127
|
+
data.linkedQuestion = null;
|
|
1128
|
+
data.showLinked = null;
|
|
1129
|
+
data.parentanswer = '';
|
|
1130
|
+
data.dateRangeType = false;
|
|
1131
|
+
reqAnswers.push( data );
|
|
1132
|
+
}
|
|
1133
|
+
} );
|
|
1134
|
+
} else {
|
|
1135
|
+
section.questions.forEach( ( ele ) => {
|
|
1136
|
+
let data = { ...sampleData };
|
|
1137
|
+
data.section_id = section.section_id;
|
|
1138
|
+
data.sectionName = section.sectionName;
|
|
1139
|
+
data.answerType = ele.answerType;
|
|
1140
|
+
data.qno = ele.qno;
|
|
1141
|
+
data.uniqueqno = ele.uniqueqno;
|
|
1142
|
+
data.uniqueqid = ele.uniqueqid;
|
|
1143
|
+
data.qname = ele.qname;
|
|
1144
|
+
data.oldQname = ele?.oldQname || ele.qname;
|
|
1145
|
+
data.answer = 'null';
|
|
1146
|
+
data.remarks = '';
|
|
1147
|
+
data.validationAnswer = '';
|
|
1148
|
+
data.Multianswer = [];
|
|
1149
|
+
data.linkType = ele.linkType;
|
|
1150
|
+
data.linkquestionenabled = ele.linkType;
|
|
1151
|
+
data.linkedQuestion = null;
|
|
1152
|
+
data.showLinked = null;
|
|
1153
|
+
data.parentanswer = '';
|
|
1154
|
+
data.dateRangeType = false;
|
|
1155
|
+
reqAnswers.push( data );
|
|
1156
|
+
} );
|
|
1157
|
+
}
|
|
1158
|
+
} );
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
let sectionFormat = [];
|
|
1162
|
+
let uniqueSections = {};
|
|
1163
|
+
reqAnswers.forEach( ( item ) => {
|
|
1164
|
+
const key = `${item.section_id}-${item.sectionName}`;
|
|
1165
|
+
if ( !uniqueSections[key] ) {
|
|
1166
|
+
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
1167
|
+
}
|
|
1168
|
+
} );
|
|
1169
|
+
const uniqueArray = Object.values( uniqueSections );
|
|
1170
|
+
for ( let section of uniqueArray ) {
|
|
1171
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id.toString() == section.id.toString() );
|
|
1172
|
+
if ( CLQSection ) {
|
|
1173
|
+
let newArray = [];
|
|
1174
|
+
let qaAnswers = CLQSection.questions;
|
|
1175
|
+
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1176
|
+
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1177
|
+
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1178
|
+
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1179
|
+
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1180
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1181
|
+
let yn = [];
|
|
1182
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1183
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1184
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1185
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1186
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1187
|
+
if ( validateAns.length ) {
|
|
1188
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1189
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1190
|
+
splitImgUrl.splice( 0, 3 );
|
|
1191
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
} else {
|
|
1196
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1197
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1198
|
+
}
|
|
1199
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1200
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1201
|
+
}
|
|
1202
|
+
yn.push( qaans[k] );
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
let structure = {};
|
|
1207
|
+
structure.qno = qaAnswers[j].qno;
|
|
1208
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1209
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1210
|
+
structure.qname = qaAnswers[j].qname;
|
|
1211
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1212
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1213
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1214
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1215
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1216
|
+
structure.remarks = requestSection[i].remarks;
|
|
1217
|
+
}
|
|
1218
|
+
structure.answers = qaAnswers[j].answers;
|
|
1219
|
+
structure.userAnswer = yn;
|
|
1220
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1221
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1222
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1223
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1224
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1225
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1226
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1227
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1228
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1229
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1230
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1231
|
+
structure.task = true;
|
|
1232
|
+
}
|
|
1233
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1234
|
+
structure.redo = false;
|
|
1235
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1236
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1237
|
+
}
|
|
1238
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1239
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1240
|
+
};
|
|
1241
|
+
newArray.push( structure );
|
|
1242
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1243
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) ); ;
|
|
1244
|
+
let ms = [];
|
|
1245
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1246
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1247
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1248
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1249
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1250
|
+
if ( validationAnswer.length ) {
|
|
1251
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1252
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1253
|
+
splitImgUrl.splice( 0, 3 );
|
|
1254
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1260
|
+
qaans[k]['validationImage']=[];
|
|
1261
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1262
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1263
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1264
|
+
if ( validationAnswer.length ) {
|
|
1265
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1266
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1267
|
+
splitImgUrl.splice( 0, 3 );
|
|
1268
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1275
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1276
|
+
}
|
|
1277
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1278
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1279
|
+
}
|
|
1280
|
+
ms.push( qaans[k] );
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
let structure = {};
|
|
1284
|
+
structure.qno = qaAnswers[j].qno;
|
|
1285
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1286
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1287
|
+
structure.qname = qaAnswers[j].qname;
|
|
1288
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1289
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1290
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1291
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1292
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1293
|
+
structure.remarks = requestSection[i].remarks;
|
|
1294
|
+
}
|
|
1295
|
+
structure.answers = qaAnswers[j].answers;
|
|
1296
|
+
structure.userAnswer = ms;
|
|
1297
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1298
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1299
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1300
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1301
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1302
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1303
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1304
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1305
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1306
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1307
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1308
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1309
|
+
structure.task = true;
|
|
1310
|
+
}
|
|
1311
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1312
|
+
structure.redo = false;
|
|
1313
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1314
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1315
|
+
}
|
|
1316
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1317
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1318
|
+
};
|
|
1319
|
+
newArray.push( structure );
|
|
1320
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1321
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1322
|
+
let mcmo = [];
|
|
1323
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1324
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1325
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1326
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1327
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1328
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1329
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1330
|
+
if ( validationAnswer.length ) {
|
|
1331
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1332
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1333
|
+
splitImgUrl.splice( 0, 3 );
|
|
1334
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
} else {
|
|
1339
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1340
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1341
|
+
}
|
|
1342
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1343
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
mcmo.push( qaans[k] );
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1352
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1353
|
+
ele.redo = false;
|
|
1354
|
+
}
|
|
1355
|
+
} );
|
|
1356
|
+
|
|
1357
|
+
let structure = {};
|
|
1358
|
+
structure.qno = qaAnswers[j].qno;
|
|
1359
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1360
|
+
structure.qno = qaAnswers[j].qno;
|
|
1361
|
+
structure.qname = qaAnswers[j].qname;
|
|
1362
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1363
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1364
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1365
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1366
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1367
|
+
structure.remarks = requestSection[i].remarks;
|
|
1368
|
+
}
|
|
1369
|
+
structure.answers = qaAnswers[j].answers;
|
|
1370
|
+
structure.userAnswer = mcmo;
|
|
1371
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1372
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1373
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1374
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1375
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1376
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1377
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1378
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1379
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1380
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1381
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1382
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1383
|
+
structure.task = true;
|
|
1384
|
+
}
|
|
1385
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1386
|
+
structure.redo = false;
|
|
1387
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1388
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1389
|
+
}
|
|
1390
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1391
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1392
|
+
};
|
|
1393
|
+
newArray.push( structure );
|
|
1394
|
+
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1395
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1396
|
+
let mcmi = [];
|
|
1397
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1398
|
+
// for (let k = 0; k < qaans.length; k++) {
|
|
1399
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1400
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1401
|
+
let newAnswer = {};
|
|
1402
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1403
|
+
if ( validationAnswer.length ) {
|
|
1404
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1405
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1406
|
+
splitImgUrl.splice( 0, 3 );
|
|
1407
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
newAnswer.answeroptionNumber = 0;
|
|
1412
|
+
newAnswer.sopFlag = false;
|
|
1413
|
+
newAnswer.validation = false;
|
|
1414
|
+
newAnswer.validationType = '';
|
|
1415
|
+
newAnswer.referenceImage = '';
|
|
1416
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1417
|
+
newAnswer.descriptivetype = '';
|
|
1418
|
+
newAnswer.showLinked = false;
|
|
1419
|
+
newAnswer.linkedQuestion = 0;
|
|
1420
|
+
newAnswer.nestedQuestion = [];
|
|
1421
|
+
newAnswer.index = s;
|
|
1422
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1423
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1424
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1425
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1426
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1427
|
+
}
|
|
1428
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1429
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1430
|
+
}
|
|
1431
|
+
mcmi.push( newAnswer );
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
// }
|
|
1436
|
+
let structure = {};
|
|
1437
|
+
structure.qno = qaAnswers[j].qno;
|
|
1438
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1439
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1440
|
+
structure.qname = qaAnswers[j].qname;
|
|
1441
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1442
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1443
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1444
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1445
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1446
|
+
structure.remarks = requestSection[i].remarks;
|
|
1447
|
+
}
|
|
1448
|
+
structure.answers = qaAnswers[j].answers;
|
|
1449
|
+
structure.userAnswer = mcmi;
|
|
1450
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1451
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1452
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1453
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1454
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1455
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1456
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1457
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1458
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1459
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1460
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1461
|
+
structure.task = true;
|
|
1462
|
+
}
|
|
1463
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1464
|
+
structure.redo = false;
|
|
1465
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1466
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1467
|
+
}
|
|
1468
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1469
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1470
|
+
};
|
|
1471
|
+
newArray.push( structure );
|
|
1472
|
+
} else {
|
|
1473
|
+
let des = [];
|
|
1474
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1475
|
+
let validationAnswer = '';
|
|
1476
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1477
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1478
|
+
}
|
|
1479
|
+
if ( validationAnswer.length ) {
|
|
1480
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1481
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1482
|
+
splitImgUrl.splice( 0, 3 );
|
|
1483
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
let ansstructure = {
|
|
1487
|
+
answer: requestSection[i].answer,
|
|
1488
|
+
answeroptionNumber: 1,
|
|
1489
|
+
sopFlag: false,
|
|
1490
|
+
validation: false,
|
|
1491
|
+
validationType: '',
|
|
1492
|
+
validationAnswer: '',
|
|
1493
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
1494
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
1495
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1496
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1497
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
1498
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
1499
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
1500
|
+
};
|
|
1501
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1502
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1503
|
+
if ( qaAnswers[j].compliance ) {
|
|
1504
|
+
if ( qaAnswers[j].compliance ) {
|
|
1505
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
1506
|
+
if ( ansArray.includes( '-' ) ) {
|
|
1507
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
1508
|
+
}
|
|
1509
|
+
if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1510
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1511
|
+
} else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1512
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1513
|
+
} else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) {
|
|
1514
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1515
|
+
} else {
|
|
1516
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1522
|
+
if ( qaAnswers[j].compliance ) {
|
|
1523
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1524
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1525
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1526
|
+
} else {
|
|
1527
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1531
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1532
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1533
|
+
}
|
|
1534
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1535
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1536
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1537
|
+
}
|
|
1538
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1539
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
1540
|
+
}
|
|
1541
|
+
des.push( ansstructure );
|
|
1542
|
+
}
|
|
1543
|
+
let structure = {};
|
|
1544
|
+
structure.qno = qaAnswers[j].qno;
|
|
1545
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1546
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1547
|
+
structure.qname = qaAnswers[j].qname;
|
|
1548
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1549
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1550
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1551
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1552
|
+
structure.remarks = requestSection[i].remarks;
|
|
1553
|
+
structure.answers = qaAnswers[j].answers;
|
|
1554
|
+
structure.userAnswer = des;
|
|
1555
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1556
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1557
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1558
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1559
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1560
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1561
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1562
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1563
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1564
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1565
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1566
|
+
structure.task = true;
|
|
1567
|
+
}
|
|
1568
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1569
|
+
structure.redo = false;
|
|
1570
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1053
1571
|
structure.redo = qaAnswers[j]?.redo;
|
|
1054
1572
|
}
|
|
1055
1573
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1071,6 +1589,19 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1071
1589
|
|
|
1072
1590
|
|
|
1073
1591
|
requestData.questionAnswers = sectionFormat;
|
|
1592
|
+
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1593
|
+
|
|
1594
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1595
|
+
for ( let section of sectionFormat ) {
|
|
1596
|
+
for ( let question of section.questions ) {
|
|
1597
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
1598
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
1599
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1074
1605
|
next();
|
|
1075
1606
|
} catch ( error ) {
|
|
1076
1607
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -1078,16 +1609,19 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1078
1609
|
}
|
|
1079
1610
|
};
|
|
1080
1611
|
|
|
1081
|
-
export async function
|
|
1612
|
+
export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next ) {
|
|
1082
1613
|
try {
|
|
1083
1614
|
let requestData = req.body;
|
|
1084
1615
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1085
|
-
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1616
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1086
1617
|
let reqAnswers = requestData.questionAnswers;
|
|
1087
1618
|
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1088
1619
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1089
1620
|
|
|
1090
1621
|
if ( requestData.submittype == 'submit' ) {
|
|
1622
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1623
|
+
requestData.submittype = 'draft';
|
|
1624
|
+
}
|
|
1091
1625
|
reqAnswers.forEach( ( reqA ) => {
|
|
1092
1626
|
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1093
1627
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
@@ -1172,26 +1706,31 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1172
1706
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1173
1707
|
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1174
1708
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1175
|
-
let qaans = qaAnswers[j].answers;
|
|
1709
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1176
1710
|
let yn = [];
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if (
|
|
1180
|
-
if (
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
splitImgUrl.
|
|
1186
|
-
|
|
1711
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1712
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1713
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1714
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1715
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1716
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1717
|
+
if ( validateAns.length ) {
|
|
1718
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1719
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1720
|
+
splitImgUrl.splice( 0, 3 );
|
|
1721
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1722
|
+
}
|
|
1187
1723
|
}
|
|
1188
1724
|
}
|
|
1725
|
+
} else {
|
|
1726
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1727
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1189
1728
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1729
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1730
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1731
|
+
}
|
|
1732
|
+
yn.push( qaans[k] );
|
|
1193
1733
|
}
|
|
1194
|
-
yn.push( qaans[k] );
|
|
1195
1734
|
}
|
|
1196
1735
|
}
|
|
1197
1736
|
let structure = {};
|
|
@@ -1203,7 +1742,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1203
1742
|
structure.runAI = qaAnswers[j].runAI;
|
|
1204
1743
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1205
1744
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1206
|
-
|
|
1745
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1746
|
+
structure.remarks = requestSection[i].remarks;
|
|
1747
|
+
}
|
|
1207
1748
|
structure.answers = qaAnswers[j].answers;
|
|
1208
1749
|
structure.userAnswer = yn;
|
|
1209
1750
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1229,41 +1770,46 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1229
1770
|
};
|
|
1230
1771
|
newArray.push( structure );
|
|
1231
1772
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1232
|
-
let qaans = qaAnswers[j].answers;
|
|
1773
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) ); ;
|
|
1233
1774
|
let ms = [];
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if (
|
|
1237
|
-
if (
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
splitImgUrl.
|
|
1243
|
-
|
|
1775
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1776
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1777
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1778
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1779
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1780
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1781
|
+
if ( validationAnswer.length ) {
|
|
1782
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1783
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1784
|
+
splitImgUrl.splice( 0, 3 );
|
|
1785
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1786
|
+
}
|
|
1244
1787
|
}
|
|
1245
1788
|
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1789
|
+
} else {
|
|
1790
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1791
|
+
qaans[k]['validationImage']=[];
|
|
1792
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1793
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1794
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1795
|
+
if ( validationAnswer.length ) {
|
|
1796
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1797
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1798
|
+
splitImgUrl.splice( 0, 3 );
|
|
1799
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1260
1803
|
}
|
|
1261
1804
|
}
|
|
1805
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1806
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1262
1807
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1808
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1809
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1810
|
+
}
|
|
1811
|
+
ms.push( qaans[k] );
|
|
1265
1812
|
}
|
|
1266
|
-
ms.push( qaans[k] );
|
|
1267
1813
|
}
|
|
1268
1814
|
}
|
|
1269
1815
|
let structure = {};
|
|
@@ -1275,7 +1821,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1275
1821
|
structure.runAI = qaAnswers[j].runAI;
|
|
1276
1822
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1277
1823
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1278
|
-
|
|
1824
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1825
|
+
structure.remarks = requestSection[i].remarks;
|
|
1826
|
+
}
|
|
1279
1827
|
structure.answers = qaAnswers[j].answers;
|
|
1280
1828
|
structure.userAnswer = ms;
|
|
1281
1829
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1302,32 +1850,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1302
1850
|
};
|
|
1303
1851
|
newArray.push( structure );
|
|
1304
1852
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1305
|
-
let qaans = qaAnswers[j].answers;
|
|
1853
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1306
1854
|
let mcmo = [];
|
|
1307
|
-
|
|
1308
|
-
let
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (
|
|
1312
|
-
if ( separatedArray[s].
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1855
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1856
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1857
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1858
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1859
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1860
|
+
if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1861
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1862
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1863
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1864
|
+
if ( validationAnswer.length ) {
|
|
1865
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1866
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1867
|
+
splitImgUrl.splice( 0, 3 );
|
|
1868
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1319
1871
|
}
|
|
1872
|
+
} else {
|
|
1873
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1874
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1875
|
+
}
|
|
1876
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1877
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1320
1878
|
}
|
|
1321
1879
|
}
|
|
1322
|
-
|
|
1323
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1324
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1880
|
+
mcmo.push( qaans[k] );
|
|
1325
1881
|
}
|
|
1326
|
-
|
|
1327
|
-
mcmo.push( qaans[k] );
|
|
1328
1882
|
}
|
|
1329
1883
|
}
|
|
1330
1884
|
}
|
|
1885
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1886
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1887
|
+
ele.redo = false;
|
|
1888
|
+
}
|
|
1889
|
+
} );
|
|
1890
|
+
|
|
1331
1891
|
let structure = {};
|
|
1332
1892
|
structure.qno = qaAnswers[j].qno;
|
|
1333
1893
|
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
@@ -1337,7 +1897,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1337
1897
|
structure.runAI = qaAnswers[j].runAI;
|
|
1338
1898
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1339
1899
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1340
|
-
|
|
1900
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1901
|
+
structure.remarks = requestSection[i].remarks;
|
|
1902
|
+
}
|
|
1341
1903
|
structure.answers = qaAnswers[j].answers;
|
|
1342
1904
|
structure.userAnswer = mcmo;
|
|
1343
1905
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1366,37 +1928,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1366
1928
|
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1367
1929
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1368
1930
|
let mcmi = [];
|
|
1931
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1369
1932
|
// for (let k = 0; k < qaans.length; k++) {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1933
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1934
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1935
|
+
let newAnswer = {};
|
|
1936
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1937
|
+
if ( validationAnswer.length ) {
|
|
1938
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1939
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1940
|
+
splitImgUrl.splice( 0, 3 );
|
|
1941
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1942
|
+
}
|
|
1379
1943
|
}
|
|
1380
|
-
}
|
|
1381
1944
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1945
|
+
newAnswer.answeroptionNumber = 0;
|
|
1946
|
+
newAnswer.sopFlag = false;
|
|
1947
|
+
newAnswer.validation = false;
|
|
1948
|
+
newAnswer.validationType = '';
|
|
1949
|
+
newAnswer.referenceImage = '';
|
|
1950
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1951
|
+
newAnswer.descriptivetype = '';
|
|
1952
|
+
newAnswer.showLinked = false;
|
|
1953
|
+
newAnswer.linkedQuestion = 0;
|
|
1954
|
+
newAnswer.nestedQuestion = [];
|
|
1955
|
+
newAnswer.index = s;
|
|
1956
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1957
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1958
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1959
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1960
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1961
|
+
}
|
|
1962
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1963
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1964
|
+
}
|
|
1965
|
+
mcmi.push( newAnswer );
|
|
1398
1966
|
}
|
|
1399
|
-
mcmi.push( newAnswer );
|
|
1400
1967
|
}
|
|
1401
1968
|
}
|
|
1402
1969
|
// }
|
|
@@ -1409,7 +1976,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1409
1976
|
structure.runAI = qaAnswers[j].runAI;
|
|
1410
1977
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1411
1978
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1412
|
-
|
|
1979
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1980
|
+
structure.remarks = requestSection[i].remarks;
|
|
1981
|
+
}
|
|
1413
1982
|
structure.answers = qaAnswers[j].answers;
|
|
1414
1983
|
structure.userAnswer = mcmi;
|
|
1415
1984
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1436,71 +2005,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1436
2005
|
newArray.push( structure );
|
|
1437
2006
|
} else {
|
|
1438
2007
|
let des = [];
|
|
1439
|
-
if (
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if ( validationAnswer.length ) {
|
|
1445
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1446
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1447
|
-
splitImgUrl.splice( 0, 3 );
|
|
1448
|
-
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
2008
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
2009
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
2010
|
+
let validationAnswer = '';
|
|
2011
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
2012
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1449
2013
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
2014
|
+
if ( validationAnswer.length ) {
|
|
2015
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
2016
|
+
if ( splitImgUrl.length > 1 ) {
|
|
2017
|
+
splitImgUrl.splice( 0, 3 );
|
|
2018
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
let ansstructure = {
|
|
2022
|
+
answer: requestSection[i].answer,
|
|
2023
|
+
answeroptionNumber: 1,
|
|
2024
|
+
sopFlag: false,
|
|
2025
|
+
validation: false,
|
|
2026
|
+
validationType: '',
|
|
2027
|
+
validationAnswer: '',
|
|
2028
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
2029
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
2030
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
2031
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
2032
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
2033
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
2034
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
2035
|
+
};
|
|
2036
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
2037
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1469
2038
|
if ( qaAnswers[j].compliance ) {
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
2039
|
+
if ( qaAnswers[j].compliance ) {
|
|
2040
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
2041
|
+
if ( ansArray.includes( '-' ) ) {
|
|
2042
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
2043
|
+
}
|
|
2044
|
+
if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
2045
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2046
|
+
} else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
2047
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2048
|
+
} else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) {
|
|
2049
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2050
|
+
} else {
|
|
2051
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
2052
|
+
}
|
|
1473
2053
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
2057
|
+
if ( qaAnswers[j].compliance ) {
|
|
2058
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
2059
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1479
2060
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1480
2061
|
} else {
|
|
1481
2062
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1482
2063
|
}
|
|
1483
2064
|
}
|
|
2065
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
2066
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2067
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1484
2068
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1489
|
-
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1490
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1491
|
-
} else {
|
|
1492
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1493
|
-
}
|
|
2069
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
2070
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2071
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1494
2072
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1500
|
-
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1501
|
-
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
2073
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
2074
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
2075
|
+
}
|
|
2076
|
+
des.push( ansstructure );
|
|
1502
2077
|
}
|
|
1503
|
-
des.push( ansstructure );
|
|
1504
2078
|
}
|
|
1505
2079
|
let structure = {};
|
|
1506
2080
|
structure.qno = qaAnswers[j].qno;
|
|
@@ -1511,7 +2085,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1511
2085
|
structure.runAI = qaAnswers[j].runAI;
|
|
1512
2086
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1513
2087
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1514
|
-
|
|
2088
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
2089
|
+
structure.remarks = requestSection[i].remarks;
|
|
2090
|
+
}
|
|
1515
2091
|
structure.answers = qaAnswers[j].answers;
|
|
1516
2092
|
structure.userAnswer = des;
|
|
1517
2093
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1552,6 +2128,18 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1552
2128
|
|
|
1553
2129
|
requestData.questionAnswers = sectionFormat;
|
|
1554
2130
|
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
2131
|
+
|
|
2132
|
+
if ( requestData.submittype == 'submit' ) {
|
|
2133
|
+
for ( let section of sectionFormat ) {
|
|
2134
|
+
for ( let question of section.questions ) {
|
|
2135
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
2136
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
2137
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
|
|
1555
2143
|
next();
|
|
1556
2144
|
} catch ( error ) {
|
|
1557
2145
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -2113,8 +2701,12 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
|
|
|
2113
2701
|
} );
|
|
2114
2702
|
} );
|
|
2115
2703
|
if ( ops.length ) {
|
|
2116
|
-
|
|
2117
|
-
|
|
2704
|
+
try {
|
|
2705
|
+
let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
|
|
2706
|
+
console.log( 'recurringFlagTracker bulkWrite result', data );
|
|
2707
|
+
} catch ( bulkErr ) {
|
|
2708
|
+
logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
|
|
2709
|
+
}
|
|
2118
2710
|
}
|
|
2119
2711
|
} catch ( error ) {
|
|
2120
2712
|
logger.error( { function: 'updateRecurringFlagTracker', error } );
|
|
@@ -2168,6 +2760,9 @@ export async function submitChecklist( req, res ) {
|
|
|
2168
2760
|
let flagCount = QuestionFlag( req, res );
|
|
2169
2761
|
updateData.questionFlag = flagCount;
|
|
2170
2762
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2763
|
+
if ( getchecklist?.[0]?.redoEdit != undefined ) {
|
|
2764
|
+
updateData.redoEdit = false;
|
|
2765
|
+
}
|
|
2171
2766
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2172
2767
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2173
2768
|
}
|
|
@@ -2440,7 +3035,8 @@ export async function submitTask( req, res ) {
|
|
|
2440
3035
|
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2441
3036
|
'message_mode': 'retriggered',
|
|
2442
3037
|
};
|
|
2443
|
-
sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
3038
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
3039
|
+
console.log( sqsResponse );
|
|
2444
3040
|
}
|
|
2445
3041
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2446
3042
|
const query1 = [
|
|
@@ -2945,6 +3541,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2945
3541
|
// const { store_id, date } = req.query;
|
|
2946
3542
|
const { date } = req.query;
|
|
2947
3543
|
const userId = req.user._id;
|
|
3544
|
+
let fromDate = new Date( req.query.date );
|
|
3545
|
+
let toDate = new Date( req.query.date );
|
|
3546
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2948
3547
|
|
|
2949
3548
|
// //Get User Based Checklist //
|
|
2950
3549
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2961,7 +3560,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2961
3560
|
...storeMatch,
|
|
2962
3561
|
};
|
|
2963
3562
|
const buildPipeline = ( matchExtraConditions = {} ) => [
|
|
2964
|
-
{ $match: { ...baseMatch, ...matchExtraConditions } },
|
|
3563
|
+
{ $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
|
|
2965
3564
|
{
|
|
2966
3565
|
$facet: {
|
|
2967
3566
|
total: [ { $count: 'total' } ],
|
|
@@ -2981,9 +3580,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2981
3580
|
},
|
|
2982
3581
|
];
|
|
2983
3582
|
|
|
2984
|
-
|
|
2985
|
-
let toDate = new Date( req.query.date );
|
|
2986
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3583
|
+
|
|
2987
3584
|
const taskBaseMatch = {
|
|
2988
3585
|
// eslint-disable-next-line camelcase
|
|
2989
3586
|
// store_id,
|
|
@@ -3032,6 +3629,8 @@ export async function dashboardv1( req, res ) {
|
|
|
3032
3629
|
processedTask.aggregate( taskQuery ),
|
|
3033
3630
|
] );
|
|
3034
3631
|
|
|
3632
|
+
console.log( checklistResult );
|
|
3633
|
+
|
|
3035
3634
|
const checklistResultData =
|
|
3036
3635
|
checklistResult.status === 'fulfilled' ?
|
|
3037
3636
|
processResult( checklistResult.value ) :
|
|
@@ -3161,6 +3760,9 @@ export async function checklistv1( req, res ) {
|
|
|
3161
3760
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3162
3761
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3163
3762
|
const userId = req.user._id;
|
|
3763
|
+
let fromDate = new Date( req.query.date );
|
|
3764
|
+
let toDate = new Date( req.query.date );
|
|
3765
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3164
3766
|
|
|
3165
3767
|
// Get User Based Checklist //
|
|
3166
3768
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3172,16 +3774,18 @@ export async function checklistv1( req, res ) {
|
|
|
3172
3774
|
// eslint-disable-next-line camelcase
|
|
3173
3775
|
// { store_id },
|
|
3174
3776
|
{ userId },
|
|
3175
|
-
{ date_string: date },
|
|
3777
|
+
{ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3176
3778
|
{ timeFlagStatus: true },
|
|
3177
3779
|
...matchExtraConditions,
|
|
3178
3780
|
clientId,
|
|
3179
3781
|
storeMatch,
|
|
3180
3782
|
];
|
|
3783
|
+
|
|
3181
3784
|
if ( checklistStatus ) {
|
|
3182
3785
|
matchConditions.push( { checklistStatus } );
|
|
3183
3786
|
}
|
|
3184
3787
|
|
|
3788
|
+
|
|
3185
3789
|
const pipeline = [
|
|
3186
3790
|
{ $match: { $and: matchConditions } },
|
|
3187
3791
|
...( searchValue ?
|
|
@@ -3234,9 +3838,7 @@ export async function checklistv1( req, res ) {
|
|
|
3234
3838
|
return pipeline;
|
|
3235
3839
|
};
|
|
3236
3840
|
|
|
3237
|
-
|
|
3238
|
-
let toDate = new Date( req.query.date );
|
|
3239
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3841
|
+
|
|
3240
3842
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3241
3843
|
const matchConditions = [
|
|
3242
3844
|
// eslint-disable-next-line camelcase
|
|
@@ -3616,7 +4218,7 @@ export async function questionList( req, res ) {
|
|
|
3616
4218
|
checkvalidation = answer.validationAnswer;
|
|
3617
4219
|
}
|
|
3618
4220
|
}
|
|
3619
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
4221
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3620
4222
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3621
4223
|
}
|
|
3622
4224
|
|