Exemple #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])
Exemple #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])
Exemple #3
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)