tango-app-api-trax 3.8.26 → 3.8.27-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 +406 -165
- package/src/controllers/mobileTrax.controller.js +782 -170
- package/src/controllers/teaxFlag.controller.js +5 -5
- package/src/controllers/trax.controller.js +6 -2
- package/src/hbs/recurringFlag.hbs +2 -2
- package/src/hbs/template.hbs +6 -2
- package/src/hbs/visit-checklist.hbs +52 -14
- package/src/routes/mobileTrax.routes.js +1 -0
- package/src/utils/visitChecklistPdf.utils.js +1 -1
|
@@ -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(
|
|
@@ -658,15 +660,15 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
|
|
|
658
660
|
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
659
661
|
section.questions.forEach( ( question ) => {
|
|
660
662
|
// question.answers.forEach( ( answer ) => {
|
|
661
|
-
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
663
|
+
let sectionQuestion = requestSection.filter( ( secQuestion ) => ( secQuestion.qname == question.oldQname || secQuestion.qname == question.qname ) && ( secQuestion.answerType == question.answerType ) );
|
|
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
|
}
|
|
@@ -1078,16 +1080,556 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1078
1080
|
}
|
|
1079
1081
|
};
|
|
1080
1082
|
|
|
1081
|
-
export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next ) {
|
|
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 = 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
|
+
qaAnswers[j].answers.forEach( ( ans ) => {
|
|
1207
|
+
delete ans?.runAIData;
|
|
1208
|
+
} );
|
|
1209
|
+
|
|
1210
|
+
let structure = {};
|
|
1211
|
+
structure.qno = qaAnswers[j].qno;
|
|
1212
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1213
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1214
|
+
structure.qname = qaAnswers[j].qname;
|
|
1215
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1216
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1217
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1218
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1219
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1220
|
+
structure.remarks = requestSection[i].remarks;
|
|
1221
|
+
}
|
|
1222
|
+
structure.answers = qaAnswers[j].answers;
|
|
1223
|
+
structure.userAnswer = yn;
|
|
1224
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1225
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1226
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1227
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1228
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1229
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1230
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1231
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1232
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1233
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1234
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1235
|
+
structure.task = true;
|
|
1236
|
+
}
|
|
1237
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1238
|
+
structure.redo = false;
|
|
1239
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1240
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1241
|
+
}
|
|
1242
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1243
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1244
|
+
};
|
|
1245
|
+
newArray.push( structure );
|
|
1246
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1247
|
+
let qaans = qaAnswers[j].answers;
|
|
1248
|
+
let ms = [];
|
|
1249
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1250
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1251
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1252
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1253
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1254
|
+
if ( validationAnswer.length ) {
|
|
1255
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1256
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1257
|
+
splitImgUrl.splice( 0, 3 );
|
|
1258
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
} else {
|
|
1263
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1264
|
+
qaans[k]['validationImage']=[];
|
|
1265
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1266
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1267
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1268
|
+
if ( validationAnswer.length ) {
|
|
1269
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1270
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1271
|
+
splitImgUrl.splice( 0, 3 );
|
|
1272
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1279
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1280
|
+
}
|
|
1281
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1282
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1283
|
+
}
|
|
1284
|
+
ms.push( qaans[k] );
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
qaAnswers[j].answers.forEach( ( ans ) => {
|
|
1288
|
+
delete ans?.runAIData;
|
|
1289
|
+
} );
|
|
1290
|
+
let structure = {};
|
|
1291
|
+
structure.qno = qaAnswers[j].qno;
|
|
1292
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1293
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1294
|
+
structure.qname = qaAnswers[j].qname;
|
|
1295
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1296
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1297
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1298
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1299
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1300
|
+
structure.remarks = requestSection[i].remarks;
|
|
1301
|
+
}
|
|
1302
|
+
structure.answers = qaAnswers[j].answers;
|
|
1303
|
+
structure.userAnswer = ms;
|
|
1304
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1305
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1306
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1307
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1308
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1309
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1310
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1311
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1312
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1313
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1314
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1315
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1316
|
+
structure.task = true;
|
|
1317
|
+
}
|
|
1318
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1319
|
+
structure.redo = false;
|
|
1320
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1321
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1322
|
+
}
|
|
1323
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1324
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1325
|
+
};
|
|
1326
|
+
newArray.push( structure );
|
|
1327
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1328
|
+
let qaans = qaAnswers[j].answers;
|
|
1329
|
+
let mcmo = [];
|
|
1330
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1331
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1332
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1333
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1334
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1335
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1336
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1337
|
+
if ( validationAnswer.length ) {
|
|
1338
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1339
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1340
|
+
splitImgUrl.splice( 0, 3 );
|
|
1341
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
} else {
|
|
1346
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1347
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1348
|
+
}
|
|
1349
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1350
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
mcmo.push( qaans[k] );
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1359
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1360
|
+
ele.redo = false;
|
|
1361
|
+
}
|
|
1362
|
+
delete ele?.runAIData;
|
|
1363
|
+
} );
|
|
1364
|
+
|
|
1365
|
+
let structure = {};
|
|
1366
|
+
structure.qno = qaAnswers[j].qno;
|
|
1367
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1368
|
+
structure.qno = qaAnswers[j].qno;
|
|
1369
|
+
structure.qname = qaAnswers[j].qname;
|
|
1370
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1371
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1372
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1373
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1374
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1375
|
+
structure.remarks = requestSection[i].remarks;
|
|
1376
|
+
}
|
|
1377
|
+
structure.answers = qaAnswers[j].answers;
|
|
1378
|
+
structure.userAnswer = mcmo;
|
|
1379
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1380
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1381
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1382
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1383
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1384
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1385
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1386
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1387
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1388
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1389
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1390
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1391
|
+
structure.task = true;
|
|
1392
|
+
}
|
|
1393
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1394
|
+
structure.redo = false;
|
|
1395
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1396
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1397
|
+
}
|
|
1398
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1399
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1400
|
+
};
|
|
1401
|
+
newArray.push( structure );
|
|
1402
|
+
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1403
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1404
|
+
let mcmi = [];
|
|
1405
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1406
|
+
// for (let k = 0; k < qaans.length; k++) {
|
|
1407
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1408
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1409
|
+
let newAnswer = {};
|
|
1410
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1411
|
+
if ( validationAnswer.length ) {
|
|
1412
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1413
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1414
|
+
splitImgUrl.splice( 0, 3 );
|
|
1415
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
newAnswer.answeroptionNumber = 0;
|
|
1420
|
+
newAnswer.sopFlag = false;
|
|
1421
|
+
newAnswer.validation = false;
|
|
1422
|
+
newAnswer.validationType = '';
|
|
1423
|
+
newAnswer.referenceImage = '';
|
|
1424
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1425
|
+
newAnswer.descriptivetype = '';
|
|
1426
|
+
newAnswer.showLinked = false;
|
|
1427
|
+
newAnswer.linkedQuestion = 0;
|
|
1428
|
+
newAnswer.nestedQuestion = [];
|
|
1429
|
+
newAnswer.index = s;
|
|
1430
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1431
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1432
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1433
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1434
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1435
|
+
}
|
|
1436
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1437
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1438
|
+
}
|
|
1439
|
+
mcmi.push( newAnswer );
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
// }
|
|
1444
|
+
let structure = {};
|
|
1445
|
+
structure.qno = qaAnswers[j].qno;
|
|
1446
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1447
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1448
|
+
structure.qname = qaAnswers[j].qname;
|
|
1449
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1450
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1451
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1452
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1453
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1454
|
+
structure.remarks = requestSection[i].remarks;
|
|
1455
|
+
}
|
|
1456
|
+
structure.answers = qaAnswers[j].answers;
|
|
1457
|
+
structure.userAnswer = mcmi;
|
|
1458
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1459
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1460
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1461
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1462
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1463
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1464
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1465
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1466
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1467
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1468
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1469
|
+
structure.task = true;
|
|
1470
|
+
}
|
|
1471
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1472
|
+
structure.redo = false;
|
|
1473
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1474
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1475
|
+
}
|
|
1476
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1477
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1478
|
+
};
|
|
1479
|
+
newArray.push( structure );
|
|
1480
|
+
} else {
|
|
1481
|
+
let des = [];
|
|
1482
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1483
|
+
let validationAnswer = '';
|
|
1484
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1485
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1486
|
+
}
|
|
1487
|
+
if ( validationAnswer.length ) {
|
|
1488
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1489
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1490
|
+
splitImgUrl.splice( 0, 3 );
|
|
1491
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
let ansstructure = {
|
|
1495
|
+
answer: requestSection[i].answer,
|
|
1496
|
+
answeroptionNumber: 1,
|
|
1497
|
+
sopFlag: false,
|
|
1498
|
+
validation: false,
|
|
1499
|
+
validationType: '',
|
|
1500
|
+
validationAnswer: '',
|
|
1501
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
1502
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
1503
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1504
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1505
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
1506
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
1507
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
1508
|
+
};
|
|
1509
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1510
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1511
|
+
if ( qaAnswers[j].compliance ) {
|
|
1512
|
+
if ( qaAnswers[j].compliance ) {
|
|
1513
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
1514
|
+
if ( ansArray.includes( '-' ) ) {
|
|
1515
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
1516
|
+
}
|
|
1517
|
+
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 ) ) {
|
|
1518
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1519
|
+
} 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 ) ) {
|
|
1520
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1521
|
+
} 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 ) {
|
|
1522
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1523
|
+
} else {
|
|
1524
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1530
|
+
if ( qaAnswers[j].compliance ) {
|
|
1531
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1532
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1533
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1534
|
+
} else {
|
|
1535
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1539
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1540
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1541
|
+
}
|
|
1542
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1543
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1544
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1545
|
+
}
|
|
1546
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1547
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
1548
|
+
}
|
|
1549
|
+
des.push( ansstructure );
|
|
1550
|
+
}
|
|
1551
|
+
let structure = {};
|
|
1552
|
+
structure.qno = qaAnswers[j].qno;
|
|
1553
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1554
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1555
|
+
structure.qname = qaAnswers[j].qname;
|
|
1556
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1557
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1558
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1559
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1560
|
+
structure.remarks = requestSection[i].remarks;
|
|
1561
|
+
structure.answers = qaAnswers[j].answers;
|
|
1562
|
+
structure.userAnswer = des;
|
|
1563
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1564
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1565
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1566
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1567
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1568
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1569
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1570
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1571
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1572
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1573
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1574
|
+
structure.task = true;
|
|
1575
|
+
}
|
|
1576
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1577
|
+
structure.redo = false;
|
|
1578
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1579
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1580
|
+
}
|
|
1581
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1582
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1583
|
+
};
|
|
1584
|
+
newArray.push( structure );
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
let sectionData = {
|
|
1590
|
+
'section_id': section.id,
|
|
1591
|
+
'sectionName': section.name,
|
|
1592
|
+
'questions': newArray,
|
|
1593
|
+
};
|
|
1594
|
+
sectionFormat.push( sectionData );
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
requestData.questionAnswers = sectionFormat;
|
|
1600
|
+
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1601
|
+
|
|
1602
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1603
|
+
for ( let section of sectionFormat ) {
|
|
1604
|
+
for ( let question of section.questions ) {
|
|
1605
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
1606
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
1607
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
next();
|
|
1614
|
+
} catch ( error ) {
|
|
1615
|
+
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1616
|
+
return res.sendError( error, 500 );
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
|
|
1620
|
+
export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next ) {
|
|
1082
1621
|
try {
|
|
1083
1622
|
let requestData = req.body;
|
|
1084
1623
|
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 } );
|
|
1624
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1086
1625
|
let reqAnswers = requestData.questionAnswers;
|
|
1087
1626
|
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1088
1627
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1089
1628
|
|
|
1090
1629
|
if ( requestData.submittype == 'submit' ) {
|
|
1630
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1631
|
+
requestData.submittype = 'draft';
|
|
1632
|
+
}
|
|
1091
1633
|
reqAnswers.forEach( ( reqA ) => {
|
|
1092
1634
|
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1093
1635
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
@@ -1172,26 +1714,31 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1172
1714
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1173
1715
|
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1174
1716
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1175
|
-
let qaans = qaAnswers[j].answers;
|
|
1717
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1176
1718
|
let yn = [];
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
if (
|
|
1180
|
-
if (
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
splitImgUrl.
|
|
1186
|
-
|
|
1719
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1720
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1721
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1722
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1723
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1724
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1725
|
+
if ( validateAns.length ) {
|
|
1726
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1727
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1728
|
+
splitImgUrl.splice( 0, 3 );
|
|
1729
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1730
|
+
}
|
|
1187
1731
|
}
|
|
1188
1732
|
}
|
|
1733
|
+
} else {
|
|
1734
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1735
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1189
1736
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1737
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1738
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1739
|
+
}
|
|
1740
|
+
yn.push( qaans[k] );
|
|
1193
1741
|
}
|
|
1194
|
-
yn.push( qaans[k] );
|
|
1195
1742
|
}
|
|
1196
1743
|
}
|
|
1197
1744
|
let structure = {};
|
|
@@ -1203,7 +1750,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1203
1750
|
structure.runAI = qaAnswers[j].runAI;
|
|
1204
1751
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1205
1752
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1206
|
-
|
|
1753
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1754
|
+
structure.remarks = requestSection[i].remarks;
|
|
1755
|
+
}
|
|
1207
1756
|
structure.answers = qaAnswers[j].answers;
|
|
1208
1757
|
structure.userAnswer = yn;
|
|
1209
1758
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1229,41 +1778,46 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1229
1778
|
};
|
|
1230
1779
|
newArray.push( structure );
|
|
1231
1780
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1232
|
-
let qaans = qaAnswers[j].answers;
|
|
1781
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) ); ;
|
|
1233
1782
|
let ms = [];
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if (
|
|
1237
|
-
if (
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
splitImgUrl.
|
|
1243
|
-
|
|
1783
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1784
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1785
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1786
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1787
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1788
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1789
|
+
if ( validationAnswer.length ) {
|
|
1790
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1791
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1792
|
+
splitImgUrl.splice( 0, 3 );
|
|
1793
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1794
|
+
}
|
|
1244
1795
|
}
|
|
1245
1796
|
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1797
|
+
} else {
|
|
1798
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1799
|
+
qaans[k]['validationImage']=[];
|
|
1800
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1801
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1802
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1803
|
+
if ( validationAnswer.length ) {
|
|
1804
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1805
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1806
|
+
splitImgUrl.splice( 0, 3 );
|
|
1807
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1260
1811
|
}
|
|
1261
1812
|
}
|
|
1813
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1814
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1262
1815
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1816
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1817
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1818
|
+
}
|
|
1819
|
+
ms.push( qaans[k] );
|
|
1265
1820
|
}
|
|
1266
|
-
ms.push( qaans[k] );
|
|
1267
1821
|
}
|
|
1268
1822
|
}
|
|
1269
1823
|
let structure = {};
|
|
@@ -1275,7 +1829,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1275
1829
|
structure.runAI = qaAnswers[j].runAI;
|
|
1276
1830
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1277
1831
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1278
|
-
|
|
1832
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1833
|
+
structure.remarks = requestSection[i].remarks;
|
|
1834
|
+
}
|
|
1279
1835
|
structure.answers = qaAnswers[j].answers;
|
|
1280
1836
|
structure.userAnswer = ms;
|
|
1281
1837
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1302,32 +1858,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1302
1858
|
};
|
|
1303
1859
|
newArray.push( structure );
|
|
1304
1860
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1305
|
-
let qaans = qaAnswers[j].answers;
|
|
1861
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1306
1862
|
let mcmo = [];
|
|
1307
|
-
|
|
1308
|
-
let
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (
|
|
1312
|
-
if ( separatedArray[s].
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1863
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1864
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1865
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1866
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1867
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1868
|
+
if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1869
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1870
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1871
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1872
|
+
if ( validationAnswer.length ) {
|
|
1873
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1874
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1875
|
+
splitImgUrl.splice( 0, 3 );
|
|
1876
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1319
1879
|
}
|
|
1880
|
+
} else {
|
|
1881
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1882
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1883
|
+
}
|
|
1884
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1885
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1320
1886
|
}
|
|
1321
1887
|
}
|
|
1322
|
-
|
|
1323
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1324
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1888
|
+
mcmo.push( qaans[k] );
|
|
1325
1889
|
}
|
|
1326
|
-
|
|
1327
|
-
mcmo.push( qaans[k] );
|
|
1328
1890
|
}
|
|
1329
1891
|
}
|
|
1330
1892
|
}
|
|
1893
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1894
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1895
|
+
ele.redo = false;
|
|
1896
|
+
}
|
|
1897
|
+
} );
|
|
1898
|
+
|
|
1331
1899
|
let structure = {};
|
|
1332
1900
|
structure.qno = qaAnswers[j].qno;
|
|
1333
1901
|
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
@@ -1337,7 +1905,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1337
1905
|
structure.runAI = qaAnswers[j].runAI;
|
|
1338
1906
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1339
1907
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1340
|
-
|
|
1908
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1909
|
+
structure.remarks = requestSection[i].remarks;
|
|
1910
|
+
}
|
|
1341
1911
|
structure.answers = qaAnswers[j].answers;
|
|
1342
1912
|
structure.userAnswer = mcmo;
|
|
1343
1913
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1366,37 +1936,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1366
1936
|
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1367
1937
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1368
1938
|
let mcmi = [];
|
|
1939
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1369
1940
|
// for (let k = 0; k < qaans.length; k++) {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1941
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1942
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1943
|
+
let newAnswer = {};
|
|
1944
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1945
|
+
if ( validationAnswer.length ) {
|
|
1946
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1947
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1948
|
+
splitImgUrl.splice( 0, 3 );
|
|
1949
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1950
|
+
}
|
|
1379
1951
|
}
|
|
1380
|
-
}
|
|
1381
1952
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1953
|
+
newAnswer.answeroptionNumber = 0;
|
|
1954
|
+
newAnswer.sopFlag = false;
|
|
1955
|
+
newAnswer.validation = false;
|
|
1956
|
+
newAnswer.validationType = '';
|
|
1957
|
+
newAnswer.referenceImage = '';
|
|
1958
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1959
|
+
newAnswer.descriptivetype = '';
|
|
1960
|
+
newAnswer.showLinked = false;
|
|
1961
|
+
newAnswer.linkedQuestion = 0;
|
|
1962
|
+
newAnswer.nestedQuestion = [];
|
|
1963
|
+
newAnswer.index = s;
|
|
1964
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1965
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1966
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1967
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1968
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1969
|
+
}
|
|
1970
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1971
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1972
|
+
}
|
|
1973
|
+
mcmi.push( newAnswer );
|
|
1398
1974
|
}
|
|
1399
|
-
mcmi.push( newAnswer );
|
|
1400
1975
|
}
|
|
1401
1976
|
}
|
|
1402
1977
|
// }
|
|
@@ -1409,7 +1984,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1409
1984
|
structure.runAI = qaAnswers[j].runAI;
|
|
1410
1985
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1411
1986
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1412
|
-
|
|
1987
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1988
|
+
structure.remarks = requestSection[i].remarks;
|
|
1989
|
+
}
|
|
1413
1990
|
structure.answers = qaAnswers[j].answers;
|
|
1414
1991
|
structure.userAnswer = mcmi;
|
|
1415
1992
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1436,71 +2013,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1436
2013
|
newArray.push( structure );
|
|
1437
2014
|
} else {
|
|
1438
2015
|
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( '/' );
|
|
2016
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
2017
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
2018
|
+
let validationAnswer = '';
|
|
2019
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
2020
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1449
2021
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
2022
|
+
if ( validationAnswer.length ) {
|
|
2023
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
2024
|
+
if ( splitImgUrl.length > 1 ) {
|
|
2025
|
+
splitImgUrl.splice( 0, 3 );
|
|
2026
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
let ansstructure = {
|
|
2030
|
+
answer: requestSection[i].answer,
|
|
2031
|
+
answeroptionNumber: 1,
|
|
2032
|
+
sopFlag: false,
|
|
2033
|
+
validation: false,
|
|
2034
|
+
validationType: '',
|
|
2035
|
+
validationAnswer: '',
|
|
2036
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
2037
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
2038
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
2039
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
2040
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
2041
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
2042
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
2043
|
+
};
|
|
2044
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
2045
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1469
2046
|
if ( qaAnswers[j].compliance ) {
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
2047
|
+
if ( qaAnswers[j].compliance ) {
|
|
2048
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
2049
|
+
if ( ansArray.includes( '-' ) ) {
|
|
2050
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
2051
|
+
}
|
|
2052
|
+
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 ) ) {
|
|
2053
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2054
|
+
} 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 ) ) {
|
|
2055
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2056
|
+
} 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 ) {
|
|
2057
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2058
|
+
} else {
|
|
2059
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
2060
|
+
}
|
|
1473
2061
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
2065
|
+
if ( qaAnswers[j].compliance ) {
|
|
2066
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
2067
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1479
2068
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1480
2069
|
} else {
|
|
1481
2070
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1482
2071
|
}
|
|
1483
2072
|
}
|
|
2073
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
2074
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2075
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1484
2076
|
}
|
|
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
|
-
}
|
|
2077
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
2078
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
2079
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1494
2080
|
}
|
|
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;
|
|
2081
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
2082
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
2083
|
+
}
|
|
2084
|
+
des.push( ansstructure );
|
|
1502
2085
|
}
|
|
1503
|
-
des.push( ansstructure );
|
|
1504
2086
|
}
|
|
1505
2087
|
let structure = {};
|
|
1506
2088
|
structure.qno = qaAnswers[j].qno;
|
|
@@ -1511,7 +2093,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1511
2093
|
structure.runAI = qaAnswers[j].runAI;
|
|
1512
2094
|
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1513
2095
|
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1514
|
-
|
|
2096
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
2097
|
+
structure.remarks = requestSection[i].remarks;
|
|
2098
|
+
}
|
|
1515
2099
|
structure.answers = qaAnswers[j].answers;
|
|
1516
2100
|
structure.userAnswer = des;
|
|
1517
2101
|
structure.linkType = qaAnswers[j].linkType;
|
|
@@ -1552,6 +2136,18 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1552
2136
|
|
|
1553
2137
|
requestData.questionAnswers = sectionFormat;
|
|
1554
2138
|
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
2139
|
+
|
|
2140
|
+
if ( requestData.submittype == 'submit' ) {
|
|
2141
|
+
for ( let section of sectionFormat ) {
|
|
2142
|
+
for ( let question of section.questions ) {
|
|
2143
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
2144
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
2145
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
|
|
1555
2151
|
next();
|
|
1556
2152
|
} catch ( error ) {
|
|
1557
2153
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -2113,8 +2709,12 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
|
|
|
2113
2709
|
} );
|
|
2114
2710
|
} );
|
|
2115
2711
|
if ( ops.length ) {
|
|
2116
|
-
|
|
2117
|
-
|
|
2712
|
+
try {
|
|
2713
|
+
let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
|
|
2714
|
+
console.log( 'recurringFlagTracker bulkWrite result', data );
|
|
2715
|
+
} catch ( bulkErr ) {
|
|
2716
|
+
logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
|
|
2717
|
+
}
|
|
2118
2718
|
}
|
|
2119
2719
|
} catch ( error ) {
|
|
2120
2720
|
logger.error( { function: 'updateRecurringFlagTracker', error } );
|
|
@@ -2130,7 +2730,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2130
2730
|
$and: [
|
|
2131
2731
|
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
2132
2732
|
{ userId: req.user._id },
|
|
2133
|
-
{ date_string: requestData.date },
|
|
2733
|
+
{ $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
|
|
2134
2734
|
],
|
|
2135
2735
|
},
|
|
2136
2736
|
} );
|
|
@@ -2150,7 +2750,9 @@ export async function submitChecklist( req, res ) {
|
|
|
2150
2750
|
let updateQuery = {};
|
|
2151
2751
|
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
2152
2752
|
updateQuery.userId = req.user._id;
|
|
2153
|
-
|
|
2753
|
+
if ( !getchecklist?.[0]?.redoStatus ) {
|
|
2754
|
+
updateQuery.date_string = requestData.date;
|
|
2755
|
+
}
|
|
2154
2756
|
|
|
2155
2757
|
let currentDateTime;
|
|
2156
2758
|
let storeTimeZone;
|
|
@@ -2168,6 +2770,9 @@ export async function submitChecklist( req, res ) {
|
|
|
2168
2770
|
let flagCount = QuestionFlag( req, res );
|
|
2169
2771
|
updateData.questionFlag = flagCount;
|
|
2170
2772
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2773
|
+
if ( getchecklist?.[0]?.redoEdit != undefined ) {
|
|
2774
|
+
updateData.redoEdit = false;
|
|
2775
|
+
}
|
|
2171
2776
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2172
2777
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2173
2778
|
}
|
|
@@ -2440,7 +3045,8 @@ export async function submitTask( req, res ) {
|
|
|
2440
3045
|
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2441
3046
|
'message_mode': 'retriggered',
|
|
2442
3047
|
};
|
|
2443
|
-
sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
3048
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
3049
|
+
console.log( sqsResponse );
|
|
2444
3050
|
}
|
|
2445
3051
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2446
3052
|
const query1 = [
|
|
@@ -2945,6 +3551,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2945
3551
|
// const { store_id, date } = req.query;
|
|
2946
3552
|
const { date } = req.query;
|
|
2947
3553
|
const userId = req.user._id;
|
|
3554
|
+
let fromDate = new Date( req.query.date );
|
|
3555
|
+
let toDate = new Date( req.query.date );
|
|
3556
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2948
3557
|
|
|
2949
3558
|
// //Get User Based Checklist //
|
|
2950
3559
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2961,7 +3570,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2961
3570
|
...storeMatch,
|
|
2962
3571
|
};
|
|
2963
3572
|
const buildPipeline = ( matchExtraConditions = {} ) => [
|
|
2964
|
-
{ $match: { ...baseMatch, ...matchExtraConditions } },
|
|
3573
|
+
{ $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
|
|
2965
3574
|
{
|
|
2966
3575
|
$facet: {
|
|
2967
3576
|
total: [ { $count: 'total' } ],
|
|
@@ -2981,9 +3590,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2981
3590
|
},
|
|
2982
3591
|
];
|
|
2983
3592
|
|
|
2984
|
-
|
|
2985
|
-
let toDate = new Date( req.query.date );
|
|
2986
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3593
|
+
|
|
2987
3594
|
const taskBaseMatch = {
|
|
2988
3595
|
// eslint-disable-next-line camelcase
|
|
2989
3596
|
// store_id,
|
|
@@ -3032,6 +3639,8 @@ export async function dashboardv1( req, res ) {
|
|
|
3032
3639
|
processedTask.aggregate( taskQuery ),
|
|
3033
3640
|
] );
|
|
3034
3641
|
|
|
3642
|
+
console.log( checklistResult );
|
|
3643
|
+
|
|
3035
3644
|
const checklistResultData =
|
|
3036
3645
|
checklistResult.status === 'fulfilled' ?
|
|
3037
3646
|
processResult( checklistResult.value ) :
|
|
@@ -3161,6 +3770,9 @@ export async function checklistv1( req, res ) {
|
|
|
3161
3770
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3162
3771
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3163
3772
|
const userId = req.user._id;
|
|
3773
|
+
let fromDate = new Date( req.query.date );
|
|
3774
|
+
let toDate = new Date( req.query.date );
|
|
3775
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3164
3776
|
|
|
3165
3777
|
// Get User Based Checklist //
|
|
3166
3778
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3172,16 +3784,18 @@ export async function checklistv1( req, res ) {
|
|
|
3172
3784
|
// eslint-disable-next-line camelcase
|
|
3173
3785
|
// { store_id },
|
|
3174
3786
|
{ userId },
|
|
3175
|
-
{ date_string: date },
|
|
3787
|
+
{ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3176
3788
|
{ timeFlagStatus: true },
|
|
3177
3789
|
...matchExtraConditions,
|
|
3178
3790
|
clientId,
|
|
3179
3791
|
storeMatch,
|
|
3180
3792
|
];
|
|
3793
|
+
|
|
3181
3794
|
if ( checklistStatus ) {
|
|
3182
3795
|
matchConditions.push( { checklistStatus } );
|
|
3183
3796
|
}
|
|
3184
3797
|
|
|
3798
|
+
|
|
3185
3799
|
const pipeline = [
|
|
3186
3800
|
{ $match: { $and: matchConditions } },
|
|
3187
3801
|
...( searchValue ?
|
|
@@ -3234,9 +3848,7 @@ export async function checklistv1( req, res ) {
|
|
|
3234
3848
|
return pipeline;
|
|
3235
3849
|
};
|
|
3236
3850
|
|
|
3237
|
-
|
|
3238
|
-
let toDate = new Date( req.query.date );
|
|
3239
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3851
|
+
|
|
3240
3852
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3241
3853
|
const matchConditions = [
|
|
3242
3854
|
// eslint-disable-next-line camelcase
|
|
@@ -3616,7 +4228,7 @@ export async function questionList( req, res ) {
|
|
|
3616
4228
|
checkvalidation = answer.validationAnswer;
|
|
3617
4229
|
}
|
|
3618
4230
|
}
|
|
3619
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
4231
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3620
4232
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3621
4233
|
}
|
|
3622
4234
|
|