iMMAP / ngm-reportDesk

The workdesk for ReportHub
0 stars 0 forks source link

RH SO Organization doesn't match with the defined organization in the platform #39

Closed rafinkanisa closed 2 years ago

rafinkanisa commented 2 years ago

Describe the bug A long time ago we have bugs where the users are able to write down their organization name while it's still not being registered in the system and not showing in the dropdown list. The bug itself has been fixed while the data is still not cleaned yet. There are many users data in the platform where the organization_id doesn't match

Context I found this when I'm trying to add organization and check on the database

To Reproduce Steps to reproduce the behavior:

  1. Login using Somalia account
  2. Go to 'https://reporthub.org/desk/#/profile/sodas'
  3. Scroll down to 'Organization'
  4. See error where "SOMALIA DEVELOPMENT ASSOCIATION IN THE SOUTH" is not listed in the system while this user is able to select it. The blank field in the interface is caused by the organization_id which doesn't match with any of the _id in organizations collection

Expected behavior Any of the organization details in other related collections (e.g. user) should follow with collections "organization". This applies to all reporting collection as well.

Screenshots

Screen Shot 2022-02-09 at 12 07 10 Screen Shot 2022-02-09 at 12 38 45

Additional context As there are many countries we'll have to take a look at, we'll do it in batches. If this issue isn't fixed, we might have an issue when producing statistics reports in the future. Please check all the users in user collection with the organization collection

fakhrihawari commented 2 years ago

Fix by using this script Script: // to check if organization collection have same info as in organizations collection

use ngmReportHub
db.organization.find({admin0pcode:"SO"}).forEach(function(o){
    var _check = db.organizations.find({organization_tag:o.organization_tag,organization:o.organization,organization_name:o.organization_name}).count();
    if(_check<1){
        print(_check + " ( " + o.organization_tag+", "+o.organization_name+", "+o.organization);
    }
})

and we do this

db.organization.find({admin0pcode:"SO",organization_tag:"pac",organization_name:"Parters for Action for Change",organization:"PAC"}).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "pac", organization_name: "Parters for Action for Change", organization: "PAC" }, { $set: { organization_name: "Physicians Across Continents (PAC)"}},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "cww", organization_name: "Concern Worldwide", organization: "CWW" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "cww", organization_name: "Concern Worldwide", organization: "CWW" }, { $set: { organization_name: "Concern World Wide" }},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "arc", organization_name: "Afghanistan Relief Committee", organization: "ARC" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "arc", organization_name: "Afghanistan Relief Committee", organization: "ARC" }, { $set: { organization_name: "America Refugees Committee" }},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "mdm", organization_name: "Medecins du Monde", organization: "Mdm" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "mdm", organization_name: "Medecins du Monde", organization: "Mdm" }, { $set: { organization_name: "Medecins du Monde", organization: "MDM" }},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "esnfi", organization_name: "Emergency Shelter Non-Food Item", organization: "SOMALIA DEVELOPMENT ASSOCIATION IN THE SOUTH" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "esnfi", organization_name: "Emergency Shelter Non-Food Item", organization: "SOMALIA DEVELOPMENT ASSOCIATION IN THE SOUTH" }, { $set: { organization_tag: "sodas", organization_name: "Somalia Development Association in the South", organization: "SODAS" }},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "qrcs", organization_name: "Qatar Red Crescent", organization: "QRCS" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "qrcs", organization_name: "Qatar Red Crescent", organization: "QRCS" }, { $set: { organization_name: "Qatar Red Crescent Society" }},{multi:true});

db.organization.find({ admin0pcode: "SO", organization_tag: "msf", organization_name: "Medecins Sans Frontieres (Doctors Without Borders)", organization: "MSF" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "msf", organization_name: "Medecins Sans Frontieres (Doctors Without Borders)", organization: "MSF" }, { $set: { organization_name: "Médecins Sans Frontières (Doctors Without Borders)" }},{multi:true})

db.organization.find({ admin0pcode: "SO", organization_tag: "reado", organization_name: "READO", organization: "Rural Education and Agriculture Development Organization (READO)" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "reado", organization_name: "READO", organization: "Rural Education and Agriculture Development Organization (READO)" }, { $set: { organization_name: "Rural Education and Agriculture Development Organization", organization: "READO" }},{multi:true})

db.organization.find({ admin0pcode: "SO", organization_tag: "macca", organization_name: "Mine Action Coordination Centre of Afghanistan", organization: "MERCYUSA" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "macca", organization_name: "Mine Action Coordination Centre of Afghanistan", organization: "MERCYUSA" }, { $set: { organization_name: "Mercy-USA for Aid and Development", organization: "Mercy-USA", organization_tag: "mercyusa" }},{multi:true})

db.organization.find({ admin0pcode: "SO", organization_tag: "hacdesa", organization_name: "HACDESA", organization: "HACDESA" }).pretty()
db.organization.update({ admin0pcode: "SO", organization_tag: "hacdesa", organization_name: "HACDESA", organization: "HACDESA" }, { $set: { organization_name: "Hadful Cooperative Construction and Development for Social Affairs" }},{multi:true})

// check other collection if have same problem

use ngmHealthCluster
var organ_collections = [
    "beneficiaries",
    "budgetprogress",
    "location",
    "project",
    "report",
    "stock",
    "stocklocation",
    "stockreport",
    "stockwarehouse",
    "targetbeneficiaries",
    "targetlocation",
];

organ_collections.forEach(function (col) {
    var _data = db.getCollection(col).aggregate([{ $match: { admin0pcode: "SO" } }]).toArray()
    print('Collection: ' + col)
    print("++++++++++++++++++++++++++++++++")
    var diff = 0;
    _data.forEach(function (y) {
        var _org = db.getSiblingDB('ngmReportHub').getCollection('organization').aggregate([{ $match: { _id: ObjectId(y.organization_id) } }]).toArray();

        if (_org.length) {
            if (_org[0].organization_tag !== y.organization_tag || _org[0].organization !== y.organization) {
                diff += 1;
                print('DIFFERENT org_tag: ' + _org[0].organization_tag + ' doc_tag: ' + y.organization_tag + ' org_organization: ' + _org[0].organization + ' doc_organization: ' + y.organization + ' org_id: ' + _org[0]._id.valueOf() + ' doc_org_id :' + y.organization_id)
            }
        }

    })
    print("++++++++++++++++++++++++++++++++")
    print("DOC wrong: " + diff);
})

use ngmHealthCluster
var organ_collections = [
    "beneficiaries",
    "budgetprogress",
    "location",
    "project",
    "report",
    "stock",
    "stocklocation",
    "stockreport",
    "stockwarehouse",
    "targetbeneficiaries",
    "targetlocation",
];

organ_collections.forEach(function (col) {
    var _data = db.getCollection(col).aggregate([{ $match: { admin0pcode: "SO" } }]).toArray()
    print('Collection: ' + col)
    print("++++++++++++++++++++++++++++++++")
    var diff = 0;
    _data.forEach(function (y) {
        var _org = db.getSiblingDB('ngmReportHub').getCollection('organization').aggregate([{ $match: { _id: ObjectId(y.organization_id) } }]).toArray();

        if (_org.length) {
            var a=0;
                b=0;
                c=0;
                note="";
            if (_org[0].organization_tag !== y.organization_tag || _org[0].organization !== y.organization) {
                if (_org[0].organization_tag !== y.organization_tag){
                    y.organization_tag = _org[0].organization_tag
                    note+="|| tag "
                    a+=1;
                }
                if (_org[0].organization !== y.organization){
                    y.organization = _org[0].organization;
                    note += "|| org"
                    b+=1;
                }

                if (y.organization_name && (_org[0].organization_name !== y.organization_name)){
                    y.organization_name = _org[0].organization_name;
                    note += "|| name"
                    c+=1;
                }

                if(a>0 || b>0 || c>0 ){
                    db.getCollection(col).save(y);
                    print("Change: "+ note);
                }
            }
        }

    })
    print("++++++++++++++++++++++++++++++++")
})

use ngmReportHub
var organ_collections = ['user', 'userhistory', 'userloginhistory']
organ_collections.forEach(function (col) {
    var _data = db.getCollection(col).aggregate([{ $match: { admin0pcode: "SO" } }]).toArray()
    print('Collection: ' + col)
    print("++++++++++++++++++++++++++++++++")
    var diff = 0;
    _data.forEach(function (y) {
        var _org = db.getSiblingDB('ngmReportHub').getCollection('organization').aggregate([{ $match: { _id: ObjectId(y.organization_id) } }]).toArray();

        if (_org.length) {
            if (_org[0].organization_tag !== y.organization_tag || _org[0].organization !== y.organization) {
                diff += 1;
                print('DIFFERENT org_tag: ' + _org[0].organization_tag + ' doc_tag: ' + y.organization_tag + ' org_organization: ' + _org[0].organization + ' doc_organization: ' + y.organization + ' org_id: ' + _org[0]._id.valueOf() + ' doc_org_id :' + y.organization_id)
            }
        }

    })
    print("++++++++++++++++++++++++++++++++")
    print("DOC wrong: " + diff);
})

use ngmReportHub
var organ_collections = ['user','userhistory','userloginhistory']
organ_collections.forEach(function (col) {
    var _data = db.getCollection(col).aggregate([{ $match: { admin0pcode: "SO" } }]).toArray()
    print('Collection: ' + col)
    print("++++++++++++++++++++++++++++++++")
    var diff = 0;
    _data.forEach(function (y) {
        var _org = db.getSiblingDB('ngmReportHub').getCollection('organization').aggregate([{ $match: { _id: ObjectId(y.organization_id) } }]).toArray();

        if (_org.length) {
            var a = 0;
            b = 0;
            c = 0;
            note = "";
            if (_org[0].organization_tag !== y.organization_tag || _org[0].organization !== y.organization) {
                if (_org[0].organization_tag !== y.organization_tag) {
                    y.organization_tag = _org[0].organization_tag
                    note += "|| tag "
                    a += 1;
                }
                if (_org[0].organization !== y.organization) {
                    y.organization = _org[0].organization;
                    note += "|| org"
                    b += 1;
                }

                if (y.organization_name && (_org[0].organization_name !== y.organization_name)) {
                    y.organization_name = _org[0].organization_name;
                    note += "|| name"
                    c += 1;
                }

                if (a > 0 || b > 0 || c > 0) {
                    db.getCollection(col).save(y);
                    print("Change: " + note);
                }
            }
        }

    })
    print("++++++++++++++++++++++++++++++++")
})
use ngmHealthCluster
db.stockreport.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).pretty()
db.stockreport.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).count()

db.stockreport.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"},{$set:{organization:"LRDO",organization_tag:"lrdo",organization_id:"5ca6445b9b7a9ce2321c7448"}},{multi:true})

use ngmReportHub
db.userhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).pretty()
db.userhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).count()
db.userhistory.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"},{$set:{organization:"LRDO",organization_tag:"lrdo",organization_name:"Livelihood Relief & Development Organization",organization_id:"5ca6445b9b7a9ce2321c7448"}},{multi:true})

db.userloginhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).pretty()
db.userloginhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"}).count()
db.userloginhistory.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Livelihood Relief & Development Organization"},{$set:{organization:"LRDO",organization_tag:"lrdo",organization_name:"Livelihood Relief & Development Organization",organization_id:"5ca6445b9b7a9ce2321c7448"}},{multi:true})

use ngmHealthCluster
db.stockreport.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).pretty()
db.stockreport.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).count()

db.stockreport.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"},{$set:{organization:"SLRO",organization_tag:"slro"}},{multi:true})

use ngmReportHub
db.userhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).pretty()
db.userhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).count()
db.userhistory.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"},{$set:{organization:"SLRO",organization_tag:"slro",organization_name:"Sustainable Livelihoods Relief Organization"}},{multi:true})

db.userloginhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).pretty()
db.userloginhistory.find({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"}).count()
db.userloginhistory.update({admin0pcode:"SO",organization_tag:"aoad",organization:"Sustainable Livelihoods Relief Organization (SLRO)"},{$set:{organization:"SLRO",organization_tag:"slro",organization_name:"Sustainable Livelihoods Relief Organization"}},{multi:true})