Esempio n. 1
0
    def post(self, request, format=None):
        print("yo")
        try:
            data = request.data
            print(data)
        except ParseError as error:
            return Response('Invalid JSON - {0}'.format(error.detail),
                            status=status.HTTP_400_BAD_REQUEST)
        response = {}
        mobile = data['user']
        otp = randint(1000, 9999)
        u = User.objects.get(username=mobile)
        print(u)
        if u is None:
            response['message'] = "Mobile number not registered"
            return JsonResponse(response,
                                safe=False,
                                content_type='application/json',
                                status=404)
        OTP.objects.filter(user=u).delete()
        if Patient.objects.filter(user=u).exists():
            p = Patient.objects.get(user=u)
            o = OTP(otp=otp, user_type="Patient", user_type_id=p.id, user=u)
            o.save()
            response['otp_id'] = o.id
            send_message(p.device.device_id, None, str(otp))
            return JsonResponse(response,
                                safe=False,
                                content_type='application/json')

        elif Doctor.objects.filter(user=u).exists():
            d = Doctor.objects.get(user=u)
            o = OTP(otp=otp, user_type="Doctor", user_type_id=d.id, user=u)
            o.save()
            response['otp_id'] = o.id
            send_message(d.device.device_id, None, str(otp))
            return JsonResponse(response,
                                safe=False,
                                content_type='application/json')
        response['message'] = "Not Registered"
        return JsonResponse(response,
                            safe=False,
                            content_type='application/json',
                            status=404)
Esempio n. 2
0
def check(request):
    timestamp_to = datetime.datetime.now() - datetime.timedelta(days=8)
    p = get_patient(request.data['patient'])
    pd = PatientData.objects.filter(
        patient_id=request.data['patient'],
        time_stamp__gte=timestamp_to).order_by('-time_stamp')
    if (len(pd) == 0):
        return
    else:
        wt = int(request.data['weight'])
        hr = int(request.data['heart_rate'])
        sys = int(request.data['systolic'])
        dia = int(request.data['diastolic'])
        for d in pd:
            if (wt != 0):
                if (abs(d.weight - wt) >= 1):
                    # print('wt')
                    change_observed[0] = True
            if (hr != 0):
                if (abs(abs(d.heart_rate) - hr) / hr >= 0.1):
                    # print('hr')
                    change_observed[1] = True
            if (sys != 0):
                if (abs(abs(d.systolic) - sys) / sys >= 0.1):
                    # print('sys')
                    change_observed[2] = True
            if (dia != 0):
                if (abs(abs(d.diastolic) - dia) / dia >= 0.1):
                    # print('dia')
                    change_observed[3] = True
        doc_message = gen_message(change_observed, p)
        if (doc_message is None):
            return
        else:
            d_id = p.doctor.device.device_id
            p_id = p.device.device_id
            send_message(d_id, None, doc_message)
            patient_message = "Please visit nearest OPD"
            send_message(p_id, None, patient_message)
            Notifications(text=doc_message, doctor=p.doctor).save()
            Notifications(text=patient_message, patient=p).save()
Esempio n. 3
0
def check_for_preeclampsia_in_current(request):
    preg_data = request.data
    patient = Patient.objects.get(pk=request.data['patient_id'])
    patient_data = PatientData.objects.filter(
        patient=request.data['patient_id']).filter(
            time_stamp=request.data['time_stamp'])
    preg_patient_details = Pregenancy.objects.get(
        patient_id=request.data['patient_id'])
    doc_message = generate_message(preg_data, patient_data, patient,
                                   preg_patient_details)
    print("lalalalalala \n\n {}".format(doc_message))
    if (doc_message is None):
        return
    else:
        doc_device_id = p.doctor.device.device_id
        patient_device_id = p.device.device_id
        send_message(doc_device_id, None, doc_message)
        patient_message = "Please visit your doctor"
        send_message(patient_device_id, None, patient_message)
        Notifications(text=doc_message, doctor=patient.doctor).save()
        Notifications(text=patient_message, patient=patient).save()
Esempio n. 4
0
 def post(self, request, format=None):
     try:
         data = request.data
         print(data)
     except ParseError as error:
         return Response('Invalid JSON - {0}'.format(error.detail),
                         status=status.HTTP_400_BAD_REQUEST)
     response = {}
     p_id = data['p_id']
     p = Patient.objects.get(pk=p_id)
     msg = data['message']
     _to = data['to']
     _from = data['from']
     response['response'] = send_message(_to, _from, msg)
     Notifications(text=msg, patient=p).save()
     return JsonResponse(response,
                         safe=False,
                         content_type='application/json')
Esempio n. 5
0
 def post(self, request, format=None):
     try:
         data = request.data
         print("Notification Data", data)
         response = {}
         p_id = data['p_id']
         p = Patient.objects.get(pk=p_id)
         msg = data['message']
         _to = data['to']
         _from = data['from']
         response['response'] = send_message(_to, _from, msg)
         Notifications(text=msg, patient=p).save()
         if (data['docId']):
             d = Doctor.objects.get(pk=data['docId'])
             print("we have doc id", d.name)
             Notifications(text="Patient " + p.name + " was advised on " +
                           msg,
                           doctor=d).save()
         return JsonResponse(response,
                             safe=False,
                             content_type='application/json')
     except ParseError as error:
         return Response('Invalid JSON - {0}'.format(error.detail),
                         status=status.HTTP_400_BAD_REQUEST)