def get_status(patient_id):
    """Determine whether or not a
    specified patient is tachycardic
    based on previously available heart rate

    Args:
        patient_id: Specified patient id

    Returns:
        d (Response instance): Whether or not the patient is
        tachycardic and the time stamp associated
        with the most recent heart rate measurement

    Excepts:
        Input Error: If specified user does not exist
        EmptyHrListError: If no heart rate
        measurements exist for specified user


    """

    connect("mongodb://*****:*****@ds037768.mlab.com:37768/bme_590")
    r = int(patient_id)
    try:
        check_id_exists(r)
    except InputError as inst4:
        logging.warning("Specified a user that does not exist")
        return jsonify({"message": inst4.message})

    try:
        check_list_empty(r)
    except EmptyHrListError as inst5:
        logging.warning("No heart rate measurements exist for specified user")
        return jsonify({"message": inst5.message})

    (age, recent_hr, recent_time_str) = data_for_is_tach(r)

    is_tach = is_tachycardic(age, recent_hr)

    if is_tach == 1:
        d = {
            "message": "patient is tachycardic",
            "timestamp of recent hr measurement": recent_time_str
        }
        logging.info("successfully returned that patient is tachycardic")
        return jsonify(d)

    if is_tach == 0:
        d = {
            "message": "patient is tachycardic",
            "timestamp of recent hr measurement": recent_time_str
        }
        logging.info("successfully returned that patient is not tachycardic")
        return jsonify(d)
def heart_rate():
    """Saves heart rate measurement and time stamp
    (associated with a patient id) to database, checks
    if patient is tachycardic, and sends email if patient is tachycardic

    Returns:
        Result (Response instance): Description noting successful
        addition of heart rate or explanation of error exception

    Excepts:
        InputError: If specified user
        does not exist
        ValidationError: If a required
        key is not present in request



    """
    connect("mongodb://*****:*****@ds037768.mlab.com:37768/bme_590")
    r = request.get_json()  # parses input request data as json
    patient_id = r["patient_id"]
    hr = r["heart_rate"]

    try:
        check_id_exists(patient_id)
    except InputError as inst3:
        logging.warning("Specified a user that does not exist")
        return jsonify({"message": inst3.message})

    try:
        validate_post_heart_rate(r)
    except ValidationError as inst4:
        logging.warning(inst4.message)
        return jsonify({"message": inst4.message})

    dt = str(datetime.datetime.now())

    id_user = User.objects.raw({"_id": patient_id})
    id_user.update({"$push": {"heart_rate": r["heart_rate"]}})
    id_user.update({"$push": {"time_stamp": dt}})
    logging.info("stored heart rate measurement and associated time stamp")

    (age, recent_hr, recent_time_str) = data_for_is_tach(patient_id)
    is_tach = is_tachycardic(age, hr)

    if is_tach == 1:
        send_email(patient_id, recent_time_str)
        logging.info("Patient {0} is tachycardic "
                     "and email sent".format(patient_id))

    result = {"message": "heartrate added successfully to the database"}
    logging.info("heartrate added successfully to the database")
    return jsonify(result)
Пример #3
0
def test_is_tachy(text, expected):
    from tachycardic import is_tachycardic
    answer = is_tachycardic(text)
    assert answer == expected
Пример #4
0
def test_is_tachycardic_validate_age():
    age = 0.08
    recent_hr = 180
    with pytest.raises(ValueError):
        is_tachycardic(age, recent_hr)
Пример #5
0
def test_is_tachycardic_parametrize(age, recent_hr, expected):
    assert is_tachycardic(age, recent_hr) == expected
Пример #6
0
def test_is_tachycardic(myIn,Expect):
	re = is_tachycardic(myIn)

	assert re == Expect
Пример #7
0
def tachycardic_test(a, expected):
    answer = is_tachycardic(a)
    assert answer == expected