Exemplo n.º 1
0
def edit_case_info(info_table, case_id, user_info):
    if not request.get_json():
        return (
            jsonify({
                "success": False,
                "error_type": "request",
                "debugmsg": "No data in request.",
            }),
            400,
        )
    # TODO Requires safer error handling
    # TODO Check table exists and exit if not (safety)
    info_table = "case" + info_table
    cursor = ext.connect_()
    columns = ext.get_cols_(info_table)
    qargs = ext.get_args_(columns, request.get_json())

    # Necessary for PUT since expect whole replacement back.
    # Will be much easier to implement this hook as a PATCH request
    # as will not have to check the previous stored data
    prior = ext.select_query_result_({"case_id": case_id},
                                     info_table)["result"][0]
    #print(prior)
    prior_meta = ext.select_query_result_({"case_id": case_id},
                                          "cases")["result"][0]
    qargs = {**qargs, **user_info}
    #print(qargs)
    qargs = hooks.put(info_table, case_id, qargs, prior)
    #print(qargs)
    if not qargs:
        # print("NO CHANGE")
        return jsonify({"success": True, "message": "no change"})
    query = ext.update_(qargs)
    query_string = "update {} ".format(
        info_table) + query[0] + " where case_id=%s"
    # print(query_string)
    cursor.execute(query_string, query[1] + (case_id, ))
    mysql.connection.commit()

    meta = {
        "info_table": info_table,
        "case_id": case_id,
        "first_name": prior_meta.get("first_name"),
        "last_name": prior_meta.get("last_name"),
        "status": prior_meta.get("status"),
        "gender": prior_meta.get("gender"),
        "dob": prior_meta.get("dob"),
    }

    log_event("edit", qargs, meta, user_info)

    return jsonify({"success": True, "debugmsg": "added"})
Exemplo n.º 2
0
def get_case_info(info_table, case_id, user_info):
    info_table = "case" + info_table
    qargs = {"case_id": case_id}
    results = ext.select_query_result_(qargs, info_table)

    if (info_table == "case_managements" and results["result"]
            is not None):  # TODO Think about whether might move this to hooks?
        cursor = ext.connect_()
        query = "select {} from {} where case_id=%s"
        extra_fields = [
            ("dob", "cases"),
            ("large_vessel_occlusion", "case_radiologies"),
            ("last_well", "cases"),
            ("ich_found", "case_radiologies"),
        ]
        for field in extra_fields:
            cursor.execute(query.format(field[0], field[1]), (case_id, ))
            field_result = cursor.fetchall()
            field_val = field_result[0][field[0]]
            if field[0] == "dob" and field_val:
                field_val = field_val.isoformat()
            elif field[0] == "last_well" and field_val:
                field_val = field_val.strftime("%Y-%m-%d %H:%M")
            results["result"][0][field[0]] = field_val
    # if info_table == 'cases':
    #    results['google_distance_api_key'] = app.config.get('GOOGLE_DISTANCE_API_KEY')

    results["success"] = True

    return jsonify(results)
Exemplo n.º 3
0
def acknowledge_case(case_id, user_info):
    # Get notification ID from POST request (TODO check how notification sender is recorded...or implement this)
    # Match notification ID to sender
    cols_ack = ["initial_location_lat", "initial_location_long"]
    if request.get_json():
        args_ack = ext.get_args_(cols_ack, request.get_json())
    else:
        args_ack = {}

    for key in ["signoff_first_name", "signoff_last_name", "signoff_role"]:
        args_ack[key] = user_info[key]

    if all(x in args_ack.keys()
           for x in ["initial_location_lat", "initial_location_long"]):
        init_lat = args_ack["initial_location_lat"]
        init_long = args_ack["initial_location_long"]
        if None not in [init_lat, init_long]:
            eta = ext.calculate_eta_(
                init_lat,
                init_long,
                app.config["HOSPITAL_LAT"],
                app.config["HOSPITAL_LONG"],
                hooks.time_now(),
                extra_seconds=600,
            )
        else:
            eta = "UNKNOWN"  # for notification
            print(
                "Debug line: initial location field latitude or longitude null."
            )
    else:
        eta = "UNKNOWN"

    args_ack["eta"] = eta
    if not args_ack:
        args_ack["signoff_first_name"] = None
        args_ack["signoff_last_name"] = None
        args_ack["signoff_role"] = None
    args_ack["hospital_name"] = app.config["HOSPITAL_NAME"]
    notify.add_message("case_acknowledged", case_id, args_ack)

    prior_meta = ext.select_query_result_({"case_id": case_id},
                                          "cases")["result"][0]
    meta = {
        "case_id": case_id,
        "first_name": prior_meta.get("first_name"),
        "last_name": prior_meta.get("last_name"),
        "status": prior_meta.get("status"),
        "gender": prior_meta.get("gender"),
        "dob": prior_meta.get("dob"),
    }
    log_event("acknowledge", args_ack, meta, user_info)

    return jsonify({"success": True})
Exemplo n.º 4
0
def delete_case(case_id, user_info):

    prior_meta = ext.select_query_result_({"case_id": case_id},
                                          "cases")["result"][0]
    meta = {
        "case_id": case_id,
        "first_name": prior_meta.get("first_name"),
        "last_name": prior_meta.get("last_name"),
        "status": prior_meta.get("status"),
        "gender": prior_meta.get("gender"),
        "dob": prior_meta.get("dob"),
    }

    cursor = ext.connect_()
    query = "delete from cases where case_id = %s"
    cursor.execute(query, (case_id, ))
    mysql.connection.commit()
    # TODO Implement check that was deleted

    log_event("delete", {}, meta, user_info)

    return jsonify({"success": True})
Exemplo n.º 5
0
def get_cases(user_info=None):
    result = ext.select_query_result_({}, "cases")
    result["success"] = True
    return jsonify(result)