Ejemplo n.º 1
0
def patient(request):
    if not authorized(request, "watch"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_name', 'patient_id', 'event', 'event_id')
    filterable_params = ['event_id']
    if request.method == "GET":
        return return_data(request, Patient, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, Patient, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 2
0
def tests(request):
    if not authorized(request, "stm"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_name', 'patient_id', 'scaled_rating1', 'scaled_rating2', 'test_results')
    filterable_params = ['patient_id']
    if request.method == "GET":
        return return_data(request, Results, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, Results, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 3
0
def safezone(request):
    if not authorized(request, "wt"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('location', 'radius', 'patient_id')
    filterable_params = ['patient_id']
    if request.method == "GET":
        return return_data(request, Safezone, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, Safezone, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 4
0
def sensors(request):
    if not authorized(request, "hs"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('location', 'sensor_type', 'sensor_id', 'patient_id')
    filterable_params = ['sensor_id', 'patient_id']
    if request.method == "GET":
        return return_data(request, Sensors, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, Sensors, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 5
0
def patient_trends(request):
    if not authorized(request, "ct"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_id', 'test_score', 'num_falls', 'num_injuries',
                 'weight', 'body_fat_percentage')
    filterable_params = ['patient_id']
    if request.method == "GET":
        return return_data(request, Trend, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, Trend, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 6
0
def patient_profile(request):
    if not authorized(request, "int"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_id', 'name', 'age', 'gender', 'doctor', 'medication',
                 'stage', 'notes')
    filterable_params = ['patient_id']
    if request.method == "GET":
        return return_data(request, PatientProfile, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, PatientProfile, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 7
0
def doctor_profile(request):
    if not authorized(request, "int"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('name', 'username', 'password', 'patient_id', 'appointment',
                 'doctor_id')
    filterable_params = ['patient_id', 'doctor_id']
    if request.method == "GET":
        return return_data(request, DoctorProfile, filterable_params)
    elif request.method == "POST":
        return ingest_data(request, DoctorProfile, my_fields)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 8
0
def caregiver(request):
    if not authorized(request, "wt"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('location', 'timestamp', 'caregiver_id')
    filterable_params = ['caregiver_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Caregiver, filterable_params)
    elif request.method == "POST":
        return ingest_data(request,
                           Caregiver,
                           my_fields,
                           json_customizer=json_timestamp_customizer)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 9
0
def logical(request):
    if not authorized(request, "ga"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_id', 'logical_score', 'timestamp', 'game_id')
    filterable_params = ['patient_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Logical, filterable_params)
    elif request.method == "POST":
        return ingest_data(request,
                           Logical,
                           my_fields,
                           json_customizer=json_timestamp_customizer)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 10
0
def episodic(request):
    if not authorized(request, "ga"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_id', 'episodic_score', 'timestamp', 'question',
                 'answer_choices', 'patient_answer', 'correct_answer')
    filterable_params = ['patient_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Episodic, filterable_params)
    elif request.method == "POST":
        return ingest_data(request,
                           Episodic,
                           my_fields,
                           json_customizer=json_timestamp_customizer)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 11
0
def patient_incidents(request):
    if not authorized(request, "ct"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('patient_id', 'incident_id', 'timestamp', 'pulse_rate',
                 'respiratory_rate', 'blood_pressure', 'incident_type',
                 'recording', 'details', 'blood_pressure')
    filterable_params = ['patient_id', 'incident_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Incident, filterable_params)
    elif request.method == "POST":
        return ingest_data(request,
                           Incident,
                           my_fields,
                           json_customizer=json_timestamp_customizer)
    else:
        return handle_invalid_request(request)
Ejemplo n.º 12
0
def patient(request):
    if not authorized(request, "wt"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('location', 'timestamp', 'patient_id')
    filterable_params = ['patient_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Patient, filterable_params)
    elif request.method == "POST":
        response = ingest_data(request,
                               Patient,
                               my_fields,
                               json_customizer=json_timestamp_customizer)
        if response.status_code == 200:
            threading.Thread(target=wandering_analysis).start()
        return response
    else:
        return handle_invalid_request(request)
Ejemplo n.º 13
0
def events(request):
    if not authorized(request, "watch"):
        return HttpResponse('Unauthorized', status=401)

    my_fields = ('event_id', 'event_description', 'event_category',
                 'timestamp')
    filterable_params = ['event_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Event, filterable_params)
    elif request.method == "POST":
        res = ingest_data(request,
                          Event,
                          my_fields,
                          json_customizer=json_timestamp_customizer)
        if res.status_code == 200:
            threading.Thread(target=fall_alert).start()
        return res
    else:
        return handle_invalid_request(request)
Ejemplo n.º 14
0
def events(request):
    if not authorized(request, "hs"):
        return HttpResponse('Unauthorized', status=401)

    def hs_customizer(json_entry):  # Not 100% "functional"... but eh?
        success1 = json_timestamp_customizer(json_entry)
        success2 = json_j2str_customizer(json_entry)
        return success1 and success2

    my_fields = ('event_type', 'sensor_id', 'sensor_type', 'data', 'timestamp')
    filterable_params = ['sensor_id', 'time_start', 'time_end']
    if request.method == "GET":
        return return_data(request, Events, filterable_params)
    elif request.method == "POST":
        response = ingest_data(request,
                               Events,
                               my_fields,
                               json_customizer=hs_customizer)
        if response.status_code == 200:
            threading.Thread(target=hs_alert).start()
        return response
    else:
        return handle_invalid_request(request)
Ejemplo n.º 15
0
def caregiver_profile(request):
    if not authorized(request, "int"):
        return HttpResponse('Unauthorized', status=401)

    # A really hack-y way to support updates w/o duplicate data. Should actually be supported via updates.
    # This also has lots of bad side effects like deleting things despite the query not being well-formed
    def caregiver_pk_hack(json_data):
        if 'caregiver_id' in json_data:
            CaregiverProfile.objects.filter(
                caregiver_id=json_data['caregiver_id']).delete()
        return True

    my_fields = ('name', 'username', 'password', 'patient_id', 'schedule',
                 'caregiver_id')
    filterable_params = ['patient_id', 'caregiver_id']
    if request.method == "GET":
        return return_data(request, CaregiverProfile, filterable_params)
    elif request.method == "POST":
        return ingest_data(request,
                           CaregiverProfile,
                           my_fields,
                           json_customizer=caregiver_pk_hack)
    else:
        return handle_invalid_request(request)