View for getting active service by location

def active_service_location(doc):
    """View for getting active service by location"""
    if doc.get('state') != 'deactivated':
        for service_id, service in doc.get('services', {}).items():
            if service.get('state') != 'deactivated':
                service['id'] = service_id
                service['organisation_id'] = doc['_id']

                location = service.get('location', None)
                if location:
                    yield location, service