def plans(): """ Plan name API find similar to spelling http://localhost:5000/plans?zipcode=36117&qry=Hum :return: json list of plan names """ results = [] if 'qry' in request.args: look_for = request.args['qry'] if look_for[0] == '*': look_for = '' zipcode = request.args['zipcode'] try: plan = request.args['plan'] except KeyError: return None # If this is a medicaid or private plan where = tools.get_location(zipcode) if where: if plan in ('medicaid', 'private'): state = where.STATE results = PlanNames.by_state(state, look_for, plan == 'medicaid') results = [r.plan_name for r in results] if state == 'OH': results.append('OH State Medicaid') elif plan == 'medicare': county_code = where.GEO.COUNTY_CODE ma_region = where.GEO.MA_REGION_CODE pdp_region = where.GEO.PDP_REGION_CODE results = Plans.find_in_county(county_code, ma_region, pdp_region, look_for) return jsonify(sorted(results))