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': '이미 등록된 병원입니다'
    })
Example #2
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
        })
Example #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)
Example #4
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})