pfitzpaddy / ngm-reportDesk

The workdesk for ReportHub
1 stars 6 forks source link

Beneficiaries without id duplication #355

Closed drfaustusfade closed 4 years ago

drfaustusfade commented 4 years ago

beneficiaries without id are duplicated when on form save button is clicked again before an updated report is returned, most often happens with users on massive reports and slow connection

drfaustusfade commented 4 years ago

https://github.com/pfitzpaddy/ngm-reportHub/pull/398

drfaustusfade commented 4 years ago

Script to find duplicates in a report (assuming records could not be exactly the same)

// script to find duplicates in a report (assuming records could not be exactly the same)

var objReportByBeneficiaryIds = {};
db.getCollection("beneficiaries").find({report_id: "report_id"}).forEach(function(d){
    _id = d._id;
    delete d.createdAt;
    delete d.updatedAt;
    delete d._id;
    delete d.report_submitted;
    objReportByBeneficiaryIds[_id] = JSON.stringify(d);
});

// print(Object.keys(objReportByBeneficiaryIds));

var arrDuplicateBeneficiaryIds = [];
var arrFirstBeneficiaryIds = [];
Object.keys(objReportByBeneficiaryIds).forEach(function(b){
//    print('beneficiary:', b);
    Object.keys(objReportByBeneficiaryIds).forEach(function(b_to_compare){
        if (b!==b_to_compare){
//            print('compare to:', b_to_compare);
            if (objReportByBeneficiaryIds[b]===objReportByBeneficiaryIds[b_to_compare] && arrFirstBeneficiaryIds.indexOf(b_to_compare)<0 && arrDuplicateBeneficiaryIds.indexOf(b_to_compare)<0){
                arrFirstBeneficiaryIds.push(b);
                arrDuplicateBeneficiaryIds.push(b_to_compare);
//                print ('duplicate:', b_to_compare);
            }
        }  
    });
});

print(arrDuplicateBeneficiaryIds);
//arrDuplicateBeneficiaryIds.forEach(function(db){print(db)});