Preprocessing.

        Flattens the object. Important data comes on the 'client'
        dictionary inside of the response. Instead, every element of the
        'client' dictionary is taken out to the main attrs dictionary.

        Removes repeated chars from firstName, middleName and lastName
        fields. Adds a firstLastName and secondLastName fields for
        clients using more than one last name.

        Adds a 'name' field joining all names in to one string. IMHO
        Mambu does an awful job with names. Besides, this is useful on
        loan accounts. They get a 'holder' field added somewhere, which
        may be an individual client, or a group. So to get the holder
        name, you just access the 'holder'['name']. No matter if you
        have a client loan or a group loan, you get the name of the
        holder.

        Creates and 'address' field that holds the very first address on
        the addresses field, to ease the use of the
        perhaps-current-or-most-important address of the client.

        Creates a field for each documentId type with the value of the
        documentId, to ease the use of docuemnt IDs. That way if you
        have a document Id named 'CURP', then you access it directly via
        the 'CURP' field, instead of going all the way through the
        idDocuments field.

def preprocess(self):
        """Preprocessing.

        Flattens the object. Important data comes on the 'client'
        dictionary inside of the response. Instead, every element of the
        'client' dictionary is taken out to the main attrs dictionary.

        Removes repeated chars from firstName, middleName and lastName
        fields. Adds a firstLastName and secondLastName fields for
        clients using more than one last name.

        Adds a 'name' field joining all names in to one string. IMHO
        Mambu does an awful job with names. Besides, this is useful on
        loan accounts. They get a 'holder' field added somewhere, which
        may be an individual client, or a group. So to get the holder
        name, you just access the 'holder'['name']. No matter if you
        have a client loan or a group loan, you get the name of the
        holder.

        Creates and 'address' field that holds the very first address on
        the addresses field, to ease the use of the
        perhaps-current-or-most-important address of the client.

        Creates a field for each documentId type with the value of the
        documentId, to ease the use of docuemnt IDs. That way if you
        have a document Id named 'CURP', then you access it directly via
        the 'CURP' field, instead of going all the way through the
        idDocuments field.
        """
        super(MambuClient,self).preprocess()

        try:
            for k,v in self['client'].items():
                self[k] = v
            del(self.attrs['client'])
        except Exception as e:
            pass

        try:
            self['firstName'] = scrc(self['firstName'], " ").strip()
        except Exception as e:
            self['firstName'] = ""
        try:
            self['middleName'] = scrc(self['middleName'], " ").strip()
        except Exception as ex:
            self['middleName'] = ""
        self['givenName']      = scrc(self["firstName"] + ((" " + self["middleName"]) if self["middleName"] != "" else ""), " ").strip()
        self['lastName']       = scrc(self['lastName'], " ").strip()
        self['firstLastName']  = " ".join(self['lastName'].split(" ")[:-1]) if len(self['lastName'].split(" ")) > 1 else self['lastName']
        self['secondLastName'] = " ".join(self['lastName'].split(" ")[-1:]) if len(self['lastName'].split(" ")) > 1 else ""

        self['name'] = scrc("%s %s" % (self['givenName'], self['lastName']), " ").strip()

        self['address'] = {}
        try:
            for name,item in self['addresses'][0].items():
                try:
                    self['addresses'][0][name] = item.strip()
                    self['address'][name] = item.strip()
                except AttributeError:
                    pass
        except (KeyError, IndexError):
            pass

        try:
            for idDoc in self['idDocuments']:
                self[idDoc['documentType']] = idDoc['documentId']
        except KeyError:
            pass