Пример #1
0
def registerhospital(request):
    hospital_email = request.POST.get('hospital_email', '')
    hospital_name = request.POST.get('hospital_name', '')
    hospital_city = request.POST.get('hospital_city', '')
    hospital_mobile_no = request.POST.get('hospital_mobile_no', '')
    hospital_address = request.POST.get('hospital_address', '')
    zip_code = request.POST.get('zip_code', '')
    password = request.POST.get('password', '')
    repassword = request.POST.get('repassword', '')
    a = hospital_address + " "
    b = hospital_city
    c = a + b
    location1 = geolocator.geocode(c)
    print(location1.address)
    if password != repassword or len(password) < 6:
        msg_pass = "******"
    else:
        msg_pass = ''
    if len(hospital_mobile_no) != 10:
        msg_phone = "phone number must be of length 10"
    else:
        msg_phone = ''
    if len(zip_code) != 6:
        msg_zip = "pin code must be of length 6"
    else:
        msg_zip = ''
    hospitals = Hospital.objects.all()
    if not (msg_pass or msg_phone or msg_zip):
        try:
            user = User.objects.create_user(username=hospital_email,
                                            email=hospital_email,
                                            password=password)
            #user.set_password(password)
            user.save()
            hosp = Hospital(hospital_email=hospital_email,
                            hospital_name=hospital_name,
                            hospital_city=hospital_city,
                            hospital_mobile_no=hospital_mobile_no,
                            hospital_address=hospital_address,
                            zip_code=zip_code,
                            hospital_latitude=location1.latitude,
                            hospital_longitude=location1.longitude)
            hosp.save()
            msg = "you are successfully registered, Go for Login!"
            return render(request, 'main.html', {
                'msg': msg,
                'hospitals': hospitals
            })
        except:
            msg_error = "this email is already registered"
            return render(request, 'register.html', {'msg_error': msg_error})
    else:
        return render(request, 'register.html', {
            'msg_pass': msg_pass,
            'msg_phone': msg_phone,
            'msg_zip': msg_zip
        })
Пример #2
0
def hospital_signup(request, a_id):
    ac = Account.objects.get(id=a_id)

    key = request.POST['ykiho']
    name = request.POST['name']
    latitude = request.POST['lat']
    longitude = request.POST['lng']
    address = request.POST['addr']
    specialCount = request.POST['spc']

    try:
        h = Hospital.objects.get(h_key=key,
                                 h_name=name,
                                 h_latitude=latitude,
                                 h_longitude=longitude)
    except ObjectDoesNotExist:
        new_h = Hospital(h_key=key,
                         h_name=name,
                         h_latitude=latitude,
                         h_longitude=longitude,
                         h_address=address,
                         h_specialCount=specialCount)

        js = json.loads(medicalCourseDefault)
        mc = medical_course(key)

        if mc['response']['body']['totalCount'] == 1:
            index = int(mc['response']['body']['items']['item']['dgsbjtCd'])
            js[index] = True
        elif mc['response']['body']['totalCount'] > 1:
            for medi in mc['response']['body']['items']['item']:
                index = int(medi['dgsbjtCd'])
                js[index] = True

        h_medicalCourse = json.dumps(js)
        new_h.h_medicalCourse = h_medicalCourse
        new_h.save()

        ac.a_hospital = new_h
        new_h.h_account = ac
        new_h.save()
        ac.save()

        return HttpResponseRedirect(
            reverse('hospital:hospitalmain', args=(new_h.id, )))

    if h.h_account is None:
        h.h_account = ac
        ac.a_hospital = h
        h.save()
        ac.save()

        return HttpResponseRedirect(
            reverse('hospital:hospitalmain', args=(h.id, )))

    return render(request, 'hospital_search.html', {
        'a': ac,
        'error': '이미 등록된 병원입니다'
    })
Пример #3
0
def hospital_insert(request):
    database = request.POST.get('database', '')
    hospital_id = shortuuid.uuid()
    name = request.POST.get('name', '')
    address = request.POST.get('address', '')
    phone = request.POST.get('phone', '')
    opening_hours = request.POST.get('opening_hours', '')
    lng = request.POST.get('lng', '')
    lat = request.POST.get('lat', '')

    hospital = Hospital(hospital_id=hospital_id,
                        name=name,
                        address=address,
                        phone=phone,
                        opening_hours=opening_hours,
                        lng=lng,
                        lat=lat)
    hospital.save(using=database)
    return HttpResponse(status=200)
Пример #4
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None

    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.profile.email_confirmed = True
        user.save()
        hospital = Hospital(user=user, email=user.email, name=user.first_name, slug=user.username).save()
        login(request, user, backend='django.contrib.auth.backends.ModelBackend')
        return redirect('complete_hospital_profile')
    else:
        return render(request, 'registration/account_activation_invalid.html')
Пример #5
0
 def test_upload_file(self):
     doctor_username = '******'
     patient_username = '******'
     password = '******'
     hospital = Hospital.create_default()
     Group.objects.create(name='Patient')
     Group.objects.create(name='Doctor')
     create_default_account(doctor_username, password, Doctor, hospital)
     create_default_account(patient_username, password, Patient, hospital)
     doctor = User.objects.get(username=doctor_username).doctor
     patient = User.objects.get(username=patient_username).patient
     diagnosis = Diagnosis.objects.create(patient=patient)
     test = Test.objects.create(doctor=doctor,
                                diagnosis=diagnosis,
                                description="",
                                results=SimpleUploadedFile(
                                    'file.txt', b'test file'))
     response = self.client.post(
         reverse('medical:upload_test_result', args=[test.id]))
     self.assertEqual(response.status_code, 302,
                      'Expected to upload test result.')
Пример #6
0
        if mc['response']['body']['totalCount'] != 0:
            if mc['response']['body']['totalCount'] == 1:
                index = int(
                    mc['response']['body']['items']['item']['dgsbjtCd'])
                js[index] = True

            else:
                for medi in mc['response']['body']['items']['item']:
                    index = int(medi['dgsbjtCd'])
                    js[index] = True

            h_medicalCourse = json.dumps(js)
            tuple = (h_key, h_name, h_lat, h_lng, h_addr, h_sdr,
                     h_medicalCourse)
            info.append(tuple)
        count += 1

    for (h_key, h_name, h_lat, h_lng, h_addr, h_sdr, h_medicalCourse) in info:
        instances.append(
            Hospital(h_key=h_key,
                     h_name=h_name,
                     h_latitude=h_lat,
                     h_longitude=h_lng,
                     h_address=h_addr,
                     h_specialCount=h_sdr,
                     h_medicalCourse=h_medicalCourse))

    Hospital.objects.bulk_create(instances)
    print('success')
Пример #7
0
 def setUpTestData(cls):
     Hospital.create_default()
Пример #8
0
    def setUpTestData(cls):
        Group.objects.create(name='Patient')

        Hospital.create_default()
Пример #9
0
def searchHospital(request, p_id):
    p = Patient.objects.get(id=p_id)
    p_lat = float(p.p_latitude)
    p_lon = float(p.p_longitude)
    hs_t = []
    hs = []

    if request.method == 'POST':
        name = request.POST['h_name']
        medicalCourse = request.POST['medical_course']
        htime = request.POST['time']

        if p_lat == 37.5585146 and p_lon == 127.0331892:
            hs = Hospital.objects.filter(h_name__contains=name)
            print(hs, file=sys.stderr)

        else:
            clinics = hosp_list(name=name, radius=100, lat=p_lat, lng=p_lon)

            if clinics['response']['body']['totalCount'] == 0:
                aasvv = 3
            elif clinics['response']['body']['totalCount'] == 1:
                temp = clinics['response']['body']['items']['item']
                h_key = temp['ykiho']
                h_name = temp['yadmNm']
                h_lat = temp['YPos']
                h_lng = temp['XPos']
                h_addr = temp['addr']
                h_sdr = temp['sdrCnt']
                js = json.loads(medicalCourseDefault)

                try:
                    new_h = Hospital.objects.get(h_name=h_name, h_key=h_key)
                except ObjectDoesNotExist:
                    mc = medical_course(h_key)

                    if mc['response']['body']['totalCount'] != 0:
                        if mc['response']['body']['totalCount'] == 1:
                            index = int(mc['response']['body']['items']['item']
                                        ['dgsbjtCd'])
                            js[index] = True
                        else:
                            for medi in mc['response']['body']['items'][
                                    'item']:
                                index = int(medi['dgsbjtCd'])
                                js[index] = True

                        h_medicalCourse = json.dumps(js)
                    else:
                        h_medicalCourse = json.dumps(js)

                    new_h = Hospital(h_key=h_key,
                                     h_name=h_name,
                                     h_latitude=h_lat,
                                     h_longitude=h_lng,
                                     h_address=h_addr,
                                     h_specialCount=h_sdr,
                                     h_medicalCourse=h_medicalCourse)
                    new_h.save()

                hs.append(new_h)

            else:
                for temp in clinics['response']['body']['items']['item']:
                    h_key = temp['ykiho']
                    h_name = temp['yadmNm']
                    h_lat = temp['YPos']
                    h_lng = temp['XPos']
                    h_addr = temp['addr']
                    h_sdr = temp['sdrCnt']
                    js = json.loads(medicalCourseDefault)

                    try:
                        new_h = Hospital.objects.get(h_name=h_name,
                                                     h_key=h_key)
                    except ObjectDoesNotExist:
                        mc = medical_course(h_key)

                        if mc['response']['body']['totalCount'] != 0:
                            if mc['response']['body']['totalCount'] == 1:
                                index = int(mc['response']['body']['items']
                                            ['item']['dgsbjtCd'])
                                js[index] = True
                            else:
                                for medi in mc['response']['body']['items'][
                                        'item']:
                                    index = int(medi['dgsbjtCd'])
                                    js[index] = True

                            h_medicalCourse = json.dumps(js)
                        else:
                            h_medicalCourse = json.dumps(js)

                        new_h = Hospital(h_key=h_key,
                                         h_name=h_name,
                                         h_latitude=h_lat,
                                         h_longitude=h_lng,
                                         h_address=h_addr,
                                         h_specialCount=h_sdr,
                                         h_medicalCourse=h_medicalCourse)
                        new_h.save()

                    hs.append(new_h)

        for h in hs:
            print(h, file=sys.stderr)
            h_lat = float(h.h_latitude)
            h_lon = float(h.h_longitude)
            if (h.get_medicalCourse()
                )[int(medicalCourse)] == True and haversine(
                    float(p_lon), float(p_lat), h_lon, h_lat) < 1:
                if htime == 'avail':
                    r = time.localtime()
                    r = r.tm_wday

                    if r == 0:
                        h_open = h.h_open1
                        h_close = h.h_close1
                    elif r == 1:
                        h_open = h.h_open2
                        h_close = h.h_close2
                    elif r == 2:
                        h_open = h.h_open3
                        h_close = h.h_close3
                    elif r == 3:
                        h_open = h.h_open4
                        h_close = h.h_close4
                    elif r == 4:
                        h_open = h.h_open5
                        h_close = h.h_close5
                    elif r == 5:
                        h_open = h.h_open6
                        h_close = h.h_close6
                    elif r == 6:
                        h_open = h.h_open7
                        h_close = h.h_close7

                    now = now = datetime.now()
                    nowTime = now.strftime('%H:%M')
                    print(nowTime, file=sys.stderr)
                    print(h_open, file=sys.stderr)
                    if nowTime > h_open and nowTime < h_close:
                        hs_t.append(h)

                else:
                    hs_t.append(h)

        print(hs_t, file=sys.stderr)
        return render(request, 'searchResult.html', {'h': hs_t, 'p': p})

    return render(request, 'searchfilter.html', {'p': p})
Пример #10
0
def create():
    return Hospital().create()
Пример #11
0
def find_id(Hosp_id):
    resp = Hospital().find_id(Hosp_id)
    return resp
Пример #12
0
def all():
    resp = Hospital().all()
    return resp
Пример #13
0
def update():
    resp = Hospital().update(request.json)
    return resp
Пример #14
0
def delete():
    resp = Hospital().delete(request.json)
    return resp
Пример #15
0
def add():
    resp = Hospital().add(request.json)
    return resp