'Import item de-duplication'

@staticmethod
def org_service_location_deduplicate(item):

    table = item.table
    data = item.data
    organisation_id = data.organisation_id
    if organisation_id:
        query = (table.organisation_id == organisation_id)
        site_id = data.site_id
        location_id = data.location_id
        location = data.location
        if site_id:
            query &= (table.site_id == site_id)
        elif location_id:
            query &= (table.location_id == location_id)
        elif location:
            query &= (table.location == location)
        else:
            query &= (((table.site_id == None) & (table.location_id == None)) & (table.location == None))
        duplicate = current.db(query).select(table.id, limitby=(0, 1)).first()
        if duplicate:
            item.id = duplicate.id
            item.method = item.METHOD.UPDATE
