Exemple #1
0
def disease(request, disease_sign='0'):
	"""
	可能的疾病和疾病信息查询
	"""
	if disease_sign == '0':
		#可能的疾病列表
		all_symptom = request.session['all_symptom']
		print "all_symptom",all_symptom
		all_answers = ""
		for key in all_symptom.keys():
			if all_symptom[key] is not None:
				all_answers = all_answers + all_symptom[key]

		answers_list = all_answers.split(",")
		disease_list = {}
		#汇总疾病id和权重
		for i in xrange(1, len(answers_list)):
			temp_list = Relation.objects.filter(question_id=answers_list[i])
			for disease in temp_list:
				if disease_list.has_key(str(disease.disease_id)):
					disease_list[str(disease.disease_id)] = int(disease_list[str(disease.disease_id)]) + int(disease.weight)
				else:
					disease_list[str(disease.disease_id)] = int(disease.weight)

		#权重排序
		all_disease = []
		max = 0
		key = ""
		for i in disease_list.keys():
			for j in disease_list.keys():
				if int(disease_list[j])>max:
					max = int(disease_list[j])
					key = j
			max = 0
			all_disease.append(key)
			del(disease_list[str(key)])

		#疾病id转换为名字
		all_disease_name = []
		for i in xrange(0, len(all_disease)):
			if i < 10:#只取前10
				disease = Disease.objects.get(id=all_disease[i])
				all_disease_name.append(disease.name)
			else:
				break
		
		strr = str(all_disease_name).replace('u\'','\'').replace('[', '').replace(']', '').replace('\'', '').replace(',', '  ')
		
		if len(strr) == 0:
			sign = "false"
		else:
			sign = "true"
		return render_to_response('disease_list.html',RequestContext(request,
								 {'strr':strr.decode("unicode-escape"), "sign":sign}))
	else:
		#单个疾病信息
		disease = Disease.objects.get(name=disease_sign)
		u.history_save(request, disease.id, "disease")
		category = Category.objects.get(id=disease.category_id)
		return render_to_response('disease_info.html',RequestContext(request,
								 {'disease':disease, "category":category}))
Exemple #2
0
def question(request, symptom='0', question='1'):
	"""
	某一个症状的附加症状
	"""
	symptom = str(symptom)

	if question != '0':
		#所有所选的主症状都放在all_symptom中
		symptom_name = Symptom.objects.get(id=symptom).name
		try:
			all_symptom = request.session['all_symptom']
		except:
			all_symptom = {}
		
		#保存用户提交的选项
		try:
			answer = request.GET.get("answer")
			a_list = answer.split(",")
			print "a_list",a_list

			for i in xrange(1, len(a_list)):
				u.history_save(request, a_list[i], "question")
		except:
			pass

		#测试是否还有下一题
		next_question = int(question)+1
		test = Question.objects.filter(symptom_id=symptom, question_no=next_question)
		if len(test) == 0:
			next_question = 0

		#保存用户选择的附加症状
		try:
			all_symptom[symptom] = all_symptom[symptom] + answer
		except:
			all_symptom[symptom] = answer
		request.session['all_symptom'] = all_symptom

		#请求的页数的数据
		question_name = ""
		question_list = Question.objects.filter(symptom_id=symptom, question_no=question)
		for question in question_list:
			question_name = question.question_name
			break

		if len(question_list) == 0:
			#该症状下无问题信息
			next = "false"
		else:
			next = "true"
		return render_to_response('question.html',RequestContext(request,
								 {'question_list':question_list, "question_name":question_name,
								  'symptom':symptom, 'next_question':next_question, "next":next }))
	else:
		#保存最后一次提交的选择
		try:
			answer = request.GET.get("answer")
			a_list = answer.split(",")
			print a_list
			for i in xrange(1, len(a_list)):
				print a_list[i]
				u.history_save(request,  a_list[i], "question")
		except:
			pass
		
		all_symptom = request.session['all_symptom']
		if all_symptom[symptom] is not None:
			all_symptom[symptom] = all_symptom[symptom] + answer

		#显示已经选择的症状
		str_symptom = u.dict_to_str(all_symptom)
		print str_symptom
		return render_to_response('all_select_symptom.html',RequestContext(request,{
					    		  'all_symptom':str_symptom}))