Ejemplo n.º 1
0
def client_post_help(request):
    if request.POST:
        name = request.POST.get('name')
        id_number = request.POST.get('id_number')
        gender = request.POST.get('gender')
        phone_number = request.POST.get('phone_number')
        village_code = request.POST.get('village_code')
        address = request.POST.get('address')
        help = {
            "name": name,
            "id_number": id_number,
            "gender": gender,
            "phone_number": phone_number,
            "address": address,
            "village_code": village_code,
            "acused_name": None,
            "acused_gender": None,
            "acused_phone_number": None,
            "acused_address": None,
            "info_type": '0',
            "witness_location": None
        }
        success = dbop.insert_help_and_report(help)
        print(success)
        if success:
            code = 200
            message = "上传成功"
        else:
            code = 500
            message = "上传失败"
    else:
        code = 1000
        message = "请求失败"
    return HttpResponse(toolbox.generate_response(code, message))
Ejemplo n.º 2
0
def client_get_poi_by_date(request):
    patients_info = dbop.get_patients_by_android()
    print(patients_info)
    if patients_info:
        poi_map = {}
        for item in patients_info:
            for daily_track in item['track']:
                if daily_track['date'] not in poi_map:
                    poi_list = []
                    for p in daily_track['pois']:
                        poi_list.append(p['name'])
                    poi_map[daily_track['date']] = poi_list
                else:
                    for p in daily_track['pois']:
                        if p['name'] not in poi_map[daily_track['date']]:
                            poi_map[daily_track['date']].append(p['name'])
        new_map = {}

        keys = sorted(poi_map.keys(), key=toolbox.datestr2timestamp)
        print(keys)
        for key in keys:
            if poi_map[key]:
                new_map[key] = list(set(poi_map[key]))
        code = 200
        message = '获取病例信息成功'
        data = new_map
    else:
        code = 500
        message = "未获取到病例信息"
        data = []
    print(data)
    return HttpResponse(toolbox.generate_response(code, message, data))
Ejemplo n.º 3
0
def client_get_disease_level(request):
    disease_level = dbop.get_disease_level()
    print(disease_level)
    if disease_level:
        code = 200
        message = '获取疫情等级成功'
        data = disease_level
    else:
        code = 500
        message = '未获取到疫情等级'
        data = []
    return HttpResponse(toolbox.generate_response(code, message, data))
Ejemplo n.º 4
0
def client_get_patients(request):
    patients_info = dbop.get_patients_by_android()
    print(patients_info)
    if patients_info:
        code = 200
        message = '获取病例信息成功'
        data = patients_info
    else:
        code = 500
        message = "未获取到病例信息"
        data = []

    return HttpResponse(toolbox.generate_response(code, message, data))
Ejemplo n.º 5
0
def client_post_register_info(request):
    if request.POST:
        name = request.POST.get('name')
        id_number = request.POST.get('id_number')
        village_code = request.POST.get('village_code')
        user = {
            "name": name,
            "id_number": id_number,
            "village_code": village_code
        }
        print(user)
        success = dbop.insert_user(user)
        if success:
            code = 200
            message = "上传成功"
        else:
            code = 500
            message = "上传失败"
    else:
        code = 1000
        message = "请求失败"
    return HttpResponse(toolbox.generate_response(code, message))
Ejemplo n.º 6
0
def get_administrative_tree(request):
    if request.GET.get("code"):
        administrative_code = request.GET.get("code")
        if administrative_code:
            administrative_tree = dbop.get_administrative_tree(administrative_code)
            code = 200
            if len(administrative_code) == 2:
                level = 0
            elif len(administrative_code) == 6:
                level = 1
            message = '获取行政区划信息成功'
            data = {"level": level, "tree": administrative_tree}
        else:
            code = 500
            message = "错误的行政区划编码"
            data = []
    else:
        code = 500
        message = "未获取到行政区划信息"
        data = []
    print(code, message, data)
    return HttpResponse(toolbox.generate_response(code, message, data))
Ejemplo n.º 7
0
def client_get_poi_by_date_high_level(request):
    patients_info = dbop.get_patients_by_android()
    print(patients_info)
    if patients_info:
        poi_map = {}
        for item in patients_info:
            for daily_track in item['track']:
                if daily_track['date'] not in poi_map:
                    poi_list = []
                    poi_list.extend(daily_track['pois'])
                    poi_map[daily_track['date']] = poi_list
                else:
                    for p in daily_track['pois']:
                        if p not in poi_map[daily_track['date']]:
                            poi_map[daily_track['date']].append(p)
        code = 200
        message = '获取病例信息成功'
        data = poi_map
    else:
        code = 500
        message = "未获取到病例信息"
        data = []

    return HttpResponse(toolbox.generate_response(code, message, data))
Ejemplo n.º 8
0
def client_post_user(request):
    if request.POST:
        name = request.POST.get('name')
        id_number = request.POST.get('id_number')
        gender = request.POST.get('gender')
        phone_number = request.POST.get('phone_number')
        village_code = request.POST.get('village_code')
        address = request.POST.get('address')
        status = request.POST.get('status')
        track = json.loads(request.POST.get('track'))
        new_track = []
        for daily_track in track:
            date = daily_track['date']
            daily_pois = daily_track['pois']
            if daily_pois:
                daily_pois = sorted(daily_pois, key=lambda s: toolbox.timestr2timestamp(s['time']['endtime']))
                new_daily_pois = []
                print(daily_pois)
                last_name = daily_pois[0]['name']
                start_time = daily_pois[0]['time']['starttime']
                end_time = daily_pois[0]['time']['endtime']
                for poi in daily_pois:
                    if poi['name'] == last_name:
                        end_time = poi['time']['endtime']
                    else:
                        new_poi = {
                            "name": last_name,
                            "coordinate": poi['coordinate'],
                            "time": {
                                "starttime": start_time,
                                "endtime": end_time
                            }
                        }
                        new_daily_pois.append(new_poi)
                        last_name = poi['name']
                        start_time = poi['time']['starttime']
                        end_time = poi['time']['endtime']
                if start_time == end_time:
                    start_time = "00:00"
                    end_time = "24:00"
                new_poi = {
                    "name": last_name,
                    "coordinate": daily_pois[-1]['coordinate'],
                    "time": {
                        "starttime": start_time,
                        "endtime": end_time
                    }
                }
                new_daily_pois.append(new_poi)
                new_track.append({
                    'date': date,
                    'pois': new_daily_pois
                })
        user = {
            "name": name,
            "id_number": id_number,
            "gender": gender,
            "phone_number": phone_number,
            "village_code": village_code,
            "address": address,
            "status": status,
            "track": json.dumps(new_track)
        }
        print(user)
        success = dbop.insert_user_info(user)
        if success:
            code = 200
            message = "上传成功"
        else:
            code = 500
            message = "上传失败"
    else:
        code = 1000
        message = "请求失败"
    return HttpResponse(toolbox.generate_response(code, message))