Exemplo n.º 1
0
def sms():
    name = request.args.get("message")
    phone_number = request.args.get("phoneNumber")
    if not name or not phone_number:
        return "The url parameters 'message' and 'phoneNumber' are required."
    # Track Event SMS RECEIVED
    track_event(current_app.config.get('GA_TRACKING_ID'),
                'smsquery',
                'receive',
                encode_cid(phone_number),
                label='lambda',
                value=2)
    msg = build_query_response(name)
    resp = send_sms(phone_number, msg[0])
    # Track Event SMS SENT
    track_event(current_app.config.get('GA_TRACKING_ID'),
                'smsquery',
                'send',
                encode_cid(phone_number),
                label='lambda',
                value=2)
    # Full url with params for sending sms, print should trigger cloudwatch
    # log on aws
    print "SMS URL: ", resp.url
    # Response from the above url, print should trigger cloudwatch log on aws
    print "SMS PROVIDER RESPONSE", resp.text
    return msg[0]
Exemplo n.º 2
0
def search():
    try:
        query = request.args.get('q')
        if not query or len(query) < 1:
            return jsonify({
                "error": "A query is required.",
                "results": "",
                "data": {
                    "nurses": []
                }
            })

        # try to get queried result first
        cached_result = cache.get(query.replace(" ", ""))
        if cached_result:
            num_cached_results = len(
                json.loads(cached_result.data)["data"]["nurses"])
            track_event(current_app.config.get('GA_TRACKING_ID'),
                        'Nurse',
                        'search',
                        request.remote_addr,
                        label=query,
                        value=num_cached_results)
            response = make_response(cached_result)
            response.headers["X-Retrieved-From-Cache"] = True
            return response

        # get nurses by that name from nursing council site
        response = {}
        nurses = get_nurses_from_nc_registry(query)
        if not nurses:
            response["message"] = "No nurse by that name found."

        # send action to google analytics
        track_event(current_app.config.get('GA_TRACKING_ID'),
                    'Nurse',
                    'search',
                    request.remote_addr,
                    label=query,
                    value=len(nurses))

        response["data"] = {"nurses": nurses}
        response["status"] = "success"

        results = jsonify(response)
        cache.set(query.replace(" ", ""), results,
                  time=345600)  # expire after 4 days
        return results

    except Exception as err:
        return jsonify({
            "status": "error",
            "message": str(err),
            "data": {
                "nurses": []
            }
        })
def search():
    try:
        query = request.args.get('q')
        if not query or len(query) < 1:
            return jsonify({
                "error": "A query is required.",
                "results": "",
                "data": {
                    "clinical_officers": []
                }
            })

        # get clinical_officers by that name from aws
        response = {}
        es = Elastic()
        clinical_officers = es.get_from_elasticsearch('clinical-officers',
                                                      query)

        if not clinical_officers:
            response["message"] = "No clinical officer by that name found."

        track_event(current_app.config.get('GA_TRACKING_ID'),
                    'Clinical-Officers',
                    'search',
                    request.remote_addr,
                    label=query,
                    value=len(clinical_officers))
        response["data"] = {"clinical_officers": clinical_officers}
        response["status"] = "success"

        results = jsonify(response)
        return results
    except Exception as err:
        return jsonify({
            "status": "error",
            "message": str(err),
            "data": {
                "clinical_officers": []
            }
        })