Ejemplo n.º 1
0
def get_ingredient_info():
    if (not MEDICAL_DIFF in session[APP][PROPOSAL]):

        A = session[APP][PROPOSAL][MEDICAL_DATA]

        url = mapi_url('get_ingredients_data')
        if url:
            lnhdp_id = session[APP][PROPOSAL][ID] if session[APP][PROPOSAL][
                ID] else ''
            B = requests.post(url, json={'lnhpd_id': lnhdp_id}).json()

            url = mapi_url('match_ingredients')
            matched, found, missing, _ = requests.post(url,
                                                       json={
                                                           'medical_data': A,
                                                           'lnhpd_data': B
                                                       }).json()
        else:
            B = LNHPD.get_ingredients_data(session[APP][PROPOSAL][ID])
            matched, found, missing, _ = LNHPD.match_ingredients(A, B)

        session[APP][PROPOSAL][MEDICAL_DIFF] = {
            "found": found,
            "missing": missing,
            "matched": matched
        }

    return jsonify(session[APP][PROPOSAL])
Ejemplo n.º 2
0
def update_ingredients():
    product = request.get_json()

    matched = product[MEDICAL_DIFF][MATCHED]
    missing = product[MEDICAL_DIFF][MISSING]
    found = product[MEDICAL_DIFF][FOUND]

    A = found + matched
    B = missing + matched

    url = mapi_url('match_ingredients')
    if url:
        matched, found, missing, _ = requests.post(url,
                                                   json={
                                                       'medical_data': A,
                                                       'lnhpd_data': B
                                                   }).json()
    else:
        matched, found, missing, _ = LNHPD.match_ingredients(A, B)

    session[APP][PROPOSAL][MEDICAL_DIFF][FOUND] = found
    session[APP][PROPOSAL][MEDICAL_DIFF][MISSING] = missing
    session[APP][PROPOSAL][MEDICAL_DIFF][MATCHED] = matched

    return jsonify(session[APP][PROPOSAL])
Ejemplo n.º 3
0
def search_pn():
    q = request.args.get('q', default='', type=str)
    url = mapi_url('top_product_search_matches')
    if (url):
        response = requests.get(url, params={'q': q}).json()
    else:
        response = LNHPD.top_product_search_matches(q)

    return jsonify(response)
Ejemplo n.º 4
0
def get_flags_info():
    warnings = session[APP][PROPOSAL][WARNINGS]
    url = mapi_url('validate_flagged_words')
    if url:
        session[APP][PROPOSAL][WARNINGS] = requests.post(url, warnings).json()
    else:
        session[APP][PROPOSAL][WARNINGS] = LNHPD.validate_flagged_words(
            warnings)
    return jsonify(session[APP][PROPOSAL])
Ejemplo n.º 5
0
def update_flags():
    product = request.get_json()
    url = mapi_url('validate_flagged_words')

    if url:
        session[APP][PROPOSAL][WARNINGS] = requests.post(
            url, json=product[WARNINGS]).json()
    else:
        session[APP][PROPOSAL][WARNINGS] = LNHPD.validate_flagged_words(
            product[WARNINGS])

    return jsonify(session[APP][PROPOSAL])
Ejemplo n.º 6
0
def best_product_matches():
    npn = request.args.get('npn', default='', type=str)
    company_name = request.args.get('company_name', default='', type=str)
    product_name = request.args.get('product_name', default='', type=str)

    url = mapi_url('best_product_matches')

    if (url):
        response = requests.post(url,
                                 json={
                                     'npn': npn,
                                     'company_name': company_name,
                                     'product_name': product_name
                                 }).json()
    else:
        response = LNHPD.best_product_matches(npn, company_name, product_name)
    return jsonify(response)
Ejemplo n.º 7
0
def get_claims_info():
    if (not CLAIM_DIFF in session[APP][PROPOSAL]):

        matched, found, missing = [], session[APP][PROPOSAL][CLAIM_DATA], []

        url = mapi_url('get_claim_data')
        if url:
            lnhdp_id = session[APP][PROPOSAL][ID] if session[APP][PROPOSAL][
                ID] else ''
            missing = requests.post(url, json={'lnhpd_id': lnhdp_id}).json()
        else:
            missing = LNHPD.get_claim_data(session[APP][PROPOSAL][ID])

        session[APP][PROPOSAL][CLAIM_DIFF] = {
            "found": found,
            "missing": missing,
            "matched": matched
        }

    return jsonify(session[APP][PROPOSAL])
Ejemplo n.º 8
0
async def get_ingredients_data(lnhpd_id: str = Body(..., embed=True)):
    """ See LNHPD.get_ingredients_data for documentation """
    return LNHPD.get_ingredients_data(lnhpd_id)
Ejemplo n.º 9
0
async def top_company_search_matches(q: str):
    return LNHPD.top_company_search_matches(q)
Ejemplo n.º 10
0
async def top_npn_search_matches(q: str):
    return LNHPD.top_npn_search_matches(q)
Ejemplo n.º 11
0
async def top_product_search_matches(q: str):
    return LNHPD.top_product_search_matches(q)
Ejemplo n.º 12
0
async def validate_flagged_words(ocr_words: List[OCR_word] = []):
    """ See LNHPD.validate_flagged_words for documentation """
    md = [l.dict(by_alias=True) for l in ocr_words]
    return LNHPD.validate_flagged_words(md)
Ejemplo n.º 13
0
async def validate_md(medical_data: List[Ingredient] = []):
    """ See LNHPD.validate_md for documentation """
    md = [l.dict(by_alias=True) for l in medical_data]
    return LNHPD.validate_md(md)
Ejemplo n.º 14
0
async def match_ingredients(medical_data: List[Ingredient] = [],
                            lnhpd_data: List[Ingredient] = []):
    """ See LNHPD.match_ingredients for documentation """
    md = [l.dict(by_alias=True) for l in medical_data]
    ld = [l.dict(by_alias=True) for l in lnhpd_data]
    return LNHPD.match_ingredients(md, ld)
Ejemplo n.º 15
0
async def best_product_matches(p: Product):
    """ See LNHPD.best_product_matches for documentation """
    return LNHPD.best_product_matches(p.npn, p.company_name, p.product_name)