Exemple #1
0
def init_doctor_data():
    hospital_list = loadHospital()
    date_list = getEveryDay()
    doctor_index = 0
    while (doctor_index < 1000):
        doctor = Doctor()
        doctor.name = getRandomName()
        doctor.age_group = random.choice(age_group_list)
        doctor.disease_list = random.sample(
            disease_list, random.choice(range(1, len(disease_list), 1)))
        doctor.doctor_office = random.choice(doctor_office_list)
        doctor.doctor_title = random.choice(doctor_title_list)
        doctor.phone = str(random.randrange(18800000001, 18899999999, 1))
        # register_day
        now_date = datetime.datetime.strptime(random.choice(date_list),
                                              "%Y-%m-%d")
        doctor.register_year = now_date.year
        doctor.register_month = now_date.month
        doctor.register_day = now_date.day
        # hospital_info
        hospital = random.choice(hospital_list)
        # print(hospital)#test output
        doctor.hospital_name = hospital[0]
        doctor.hospital_level = hospital[1]
        doctor.province = hospital[2]
        doctor.city = hospital[3]
        doctor.longitude = float(hospital[4])
        doctor.latitude = float(hospital[5])
        doctor.save()
        doctor_index += 1
def init_doctor_data():
    client = MongoClient('mongodb://localhost:27017/')
    db = client['development_mongodb']

    disease_list = ['糖尿病', '痛风/高尿酸血症', '甲状腺疾病', '骨代谢性疾病', '其他内分泌疾病']
    age_group_list = [
        '小于18岁', '18-30岁', '31-35岁', '41-45岁', '46-50岁', '51-55岁', '56-60岁',
        '60岁以上'
    ]
    doctor_office_list = ['糖尿病科', '内分泌科', '风湿科', '甲乳外科', '甲状腺外科', '综合内科', '全科']
    doctor_title_list = ['住院医师', '主治医师', '副主任医师', '主任医师']
    hospital_list = loadHospital()
    date_list = getEveryDay()
    doctor_index = 0
    while (doctor_index < 1000):
        doctor = Doctor()
        doctor.name = getRandomName()
        doctor.age_group = random.choice(age_group_list)
        doctor.disease_list = random.sample(
            disease_list, random.choice(range(1, len(disease_list), 1)))
        doctor.doctor_office = random.choice(doctor_office_list)
        doctor.doctor_title = random.choice(doctor_title_list)
        doctor.phone = str(random.randrange(18800000001, 18899999999, 1))
        # register_day
        now_date = datetime.datetime.strptime(random.choice(date_list),
                                              "%Y-%m-%d")
        doctor.register_year = now_date.year
        doctor.register_month = now_date.month
        doctor.register_day = now_date.day
        # hospital_info
        hospital = random.choice(hospital_list)
        #print(hospital)#test output
        doctor.hospital_name = hospital[0]
        doctor.hospital_level = hospital[1]
        doctor.province = hospital[2]
        doctor.city = hospital[3]
        doctor.longitude = float(hospital[4])
        doctor.latitude = float(hospital[5])

        doctor_json = {
            'doctor_name': doctor.name,
            'age_group': doctor.age_group,
            'disease_list': doctor.disease_list,
            'doctor_office': doctor.doctor_office,
            'doctor_title': doctor.doctor_title,
            'phone': doctor.phone,
            '': doctor.register_year,
            '': doctor.register_month,
            '': doctor.register_day,
            'hospital_name': doctor.hospital_name,
            'hospital_level': doctor.hospital_level,
            'province': doctor.province,
            'city': doctor.city,
            'longitude': doctor.longitude,
            'latitude': doctor.latitude
        }
        db.doctors.insert_one(doctor_json)
        doctor_index += 1