def removeclientname(text, clientID):
    if stclients.count({"clientID": int(clientID)}) > 0:
        clientData = stclients.find({"clientID": int(clientID)})
        cleanName = clientData[0]['Name']
        if 'synonyms' in clientData[0]:
            synonyms = clientData[0]['synonyms']
            synonyms = synonyms.split("|!@#$%|")
            synonyms.sort(key=len, reverse=True)
            for syn in synonyms:
                text = utility.find_word_scrub(text, syn)
        text = utility.find_word_scrub(text, cleanName)
    return text
def removeclientname(text, clientID, stclients):
    clientNames = [
        item for item in stclients if item['clientID'] == int(clientID)
    ]
    clientData = clientNames
    if clientData:
        cleanName = clientData[0]['Name']
        if 'synonyms' in clientData[0]:
            synonyms = clientData[0]['synonyms']
            synonyms = synonyms.split("|!@#$%|")
            synonyms.sort(key=len, reverse=True)
            for syn in synonyms:
                text = utility.find_word_scrub(text, syn)
        text = utility.find_word_scrub(text, cleanName)
    return text
def scrubcandidate(text, candidateId):
    # Not using projection as all documents may not have the projected items
    candidates = stCandidateCollection.find({'candidateid': int(candidateId)})
    if candidates.count() > 0:
        candidate = candidates[0]
        if 'firstName' in candidate:
            if candidate['firstName'] != '':
                text = utility.find_word_scrub(text, candidate['firstName'])
        if 'middleName' in candidate:
            if candidate['middleName'] != '':
                text = utility.find_word_scrub(text, candidate['middleName'])
        if 'lastName' in candidate:
            if candidate['lastName'] != '':
                text = utility.find_word_scrub(text, candidate['lastName'])
    return text
def scrubcandidate(text, candidateId, candidates):
    candidateList = [
        item for item in candidates if item['candidateid'] == int(candidateId)
    ]
    if candidateList:
        candidate = candidateList[0]
        if 'firstName' in candidate:
            if candidate['firstName'] != '':
                text = utility.find_word_scrub(text, candidate['firstName'])
        if 'middleName' in candidate:
            if candidate['middleName'] != '':
                text = utility.find_word_scrub(text, candidate['middleName'])
        if 'lastName' in candidate:
            if candidate['lastName'] != '':
                text = utility.find_word_scrub(text, candidate['lastName'])
    return text
def removemspusername(text, mspID, mspusers):
    mspNames = [
        item['Name'] for item in mspusers if item['mspID'] == int(mspID)
    ]
    if mspNames:
        mspUserName = mspNames[0]
        text = utility.find_word_scrub(text, mspUserName)
    return text
def removesuppliername(text, supplierName, extensions):
    supplier = ''
    extensionremove = []
    extentions = extensions
    for exe in extentions:
        supplier = supplierName + ' ' + exe['Name']
        text = utility.find_word_scrub(text, supplier)
        extensionremove.append(exe['Name'])

    text = utility.find_word_scrub(text, supplierName)
    # ------------------------------------------------------------------------------
    # removing extension and searching for the supplier name
    for exe in extensionremove:
        supplier = utility.find_word_scrub(supplierName, exe)
        supplier = supplier.strip()
        text = utility.find_word_scrub(text, supplier)


# ------------------------------------------------------------------------------
    return text
def removephonenumber_new(text, configdocs):
    country_codes = []
    country_codes = string_to_array(configdocs[0]['countryCodes'], ',',
                                    country_codes)
    for code in country_codes:
        matches = phonenumbers.PhoneNumberMatcher(text, code)
        for match in matches:
            isdate = phone_date_filter(match)
            if not isdate:
                text = utility.find_word_scrub(text, match.raw_string)
    return text
def removesuppliername(text, supplierName):
    extentions = extentionexceptions.find({})
    # extentions.sort(key=len, reverse=True)
    supplier = ''
    extensionremove = []
    for exe in extentions:
        supplier = supplierName + ' ' + exe['Name']
        text = utility.find_word_scrub(text, supplier)
        extensionremove.append(exe['Name'])

    text = utility.find_word_scrub(text, supplierName)
    # ------------------------------------------------------------------------------
    # removing extension and searching for the supplier name
    for exe in extensionremove:
        supplier = utility.find_word_scrub(supplierName, exe)
        supplier = supplier.strip()
        text = utility.find_word_scrub(text, supplier)


# ------------------------------------------------------------------------------
    return text
def removemspusername(text, mspID):
    if mspusers.count({"mspID": int(mspID)}) > 0:
        mspUserData = mspusers.find({"mspID": int(mspID)})
        mspUserName = mspUserData[0]['Name']
        text = utility.find_word_scrub(text, mspUserName)
    return text