'Returns the first item with matching parameters.
Creates item if it doesn\'t exist.'

def _get_item(self, technology, region, account, name):

    account_result = Account.query.filter((Account.name == account)).first()
    if (not account_result):
        raise Exception('Account    with    name    [{}]    not    found.'.format(account))
    item = Item.query.join((Technology, (Item.tech_id == Technology.id))).join((Account, (Item.account_id == Account.id))).filter((Technology.name == technology)).filter((Account.name == account)).filter((Item.region == region)).filter((Item.name == name)).all()
    if (len(item) > 1):
        raise Exception('Found    multiple    items    for    tech:    {}    region:    {}    account:    {}    and    name:    {}'.format(technology, region, account, name))
    if (len(item) == 1):
        item = item[0]
    else:
        item = None
    if (not item):
        technology_result = Technology.query.filter((Technology.name == technology)).first()
        if (not technology_result):
            technology_result = Technology(name=technology)
            db.session.add(technology_result)
            db.session.commit()
            app.logger.info('Creating    a    new    Technology:    {}    -    ID:    {}'.format(technology, technology_result.id))
        item = Item(tech_id=technology_result.id, region=region, account_id=account_result.id, name=name)
        db.session.add(item)
        db.session.commit()
        db.session.refresh(item)
    return item
