def real_read_card(request): resident_name = request.POST.get('name') birthday = request.POST.get('birthday') gender = request.POST.get('gender') nation = request.POST.get('nation') address = request.POST.get('address') identity = request.POST.get('identity') try: resident = Resident.objects.get(identity=identity) except Resident.DoesNotExist: resident = Resident() resident.name = resident_name resident.gender = gender if len(birthday) != 8: resident.birthday = '1900-01-01' else: resident.birthday = birthday[0:4] + '-' + birthday[ 4:6] + '-' + birthday[6:8] resident.nation = nation resident.address = address resident.identity = identity resident.save() request.session['resident_id'] = resident.id request.session['resident_name'] = resident.name request.session['resident_ehr_no'] = resident.ehr_no json_data = model_to_dict(resident, fields=['id', 'name', 'ehr_no']) return JsonResponse(json_data)
def test_card(request): name = request.GET.get('name') birthday = request.GET.get('birthday') gender = request.GET.get('gender') nation = request.GET.get('nation') address = request.GET.get('address') identity = request.GET.get('identity') try: resident = Resident.objects.get(identity=identity) except Resident.DoesNotExist: resident = Resident() resident.name = name resident.gender = gender try: year, month, day = int(birthday[:4]), int(birthday[4:6]), int( birthday[6:8]) except Exception: pass else: resident.birthday = date(year, month, day) resident.nation = nation resident.address = address resident.identity = identity resident.save() finally: candidates = list() candidates.append(resident) if resident.family: for member in resident.family.members.all(): if member is not resident and member.identity is None: candidates.append(member) json_candidates = serializers.serialize("json", candidates) return HttpResponse(json_candidates, content_type="application/javascript")
def personal_info_submit(request): resident_id = request.POST.get('resident_id') if resident_id: resident_id = int(resident_id) resident = Resident.objects.get(id=resident_id) else: # 创建一个新的居民对象 from services.utils import gender_map gender = gender_map().index(request.POST.get('gender')) nation = request.POST.get('nation') if nation == u'少数民族' and request.POST.get('nation_extra'): nation = request.POST.get('nation_extra') if request.user.userprofile.clinic.region.is_town: town = request.user.userprofile.clinic.region village = None else: village = request.user.userprofile.clinic.region town = village.town resident = Resident(name=request.POST.get('resident_name'), gender=gender, nation=nation, town=town, village=village, birthday=request.POST.get('birthday'), address=request.POST.get('address'), identity=request.POST.get('identity'), mobile=request.POST.get('phone'), create_by=request.user) resident.save() form = PersonalInfoForm(request.POST) if form.is_valid(): personal_info = form.save() resident.personal_info_table = personal_info record = WorkRecord(resident=resident, provider=request.user, service_item_alias='personal_info_table', item_id=personal_info.id) record.save() ''' 以下是自动生成健康档案编号的方法,但是需求手动设置健康档案编号 if resident.village: village = resident.village village.ehr_no += 1 resident.ehr_no = village.id + '%05d' % village.ehr_no village.save() else: resident.ehr_no = '13108200000000000' ''' if resident.ehr_no is None: ehr_village_no = int(request.POST.get('ehr_village_no')) # 由于是必填项,而且是数字类型,所以在此不必检查类型 ehr_unique_no = int(request.POST.get('ehr_unique_no')) # 由于是必填项,而且是数字类型,所以在此不必检查类型 town_no = request.user.userprofile.clinic.town_clinic.region.id resident.ehr_no = town_no + '%03d' % ehr_village_no + '%05d' % ehr_unique_no resident.save() if resident.identity is None and personal_info.identity is not None: resident.identity = personal_info.identity resident.save() elif resident.identity is not None and personal_info.identity is not None: if resident.identity != personal_info.identity: resident.identity = personal_info.identity resident.save() if resident.mobile is None and personal_info.phone is not None: resident.mobile = personal_info.phone resident.save() elif resident.mobile is not None and personal_info.phone is not None: if resident.mobile != personal_info.phone: resident.mobile = personal_info.phone resident.save() success = True else: success = False return json_result({'success': success, 'resident_id': resident.id})
def personal_info_submit(request): resident_id = request.POST.get('resident_id') if resident_id: resident_id = int(resident_id) resident = Resident.objects.get(id=resident_id) else: # 创建一个新的居民对象 from services.utils import gender_map gender = gender_map().index(request.POST.get('gender')) nation = request.POST.get('nation') if nation == u'少数民族' and request.POST.get('nation_extra'): nation = request.POST.get('nation_extra') if request.user.userprofile.clinic.region.is_town: town = request.user.userprofile.clinic.region village = None else: village = request.user.userprofile.clinic.region town = village.town resident = Resident(name=request.POST.get('resident_name'), gender=gender, nation=nation, town=town, village=village, birthday=request.POST.get('birthday'), address=request.POST.get('address'), identity=request.POST.get('identity'), mobile=request.POST.get('phone'), create_by=request.user) resident.save() form = PersonalInfoForm(request.POST) if form.is_valid(): personal_info = form.save() resident.personal_info_table = personal_info record = WorkRecord(resident=resident, provider=request.user, service_item_alias='personal_info_table', item_id=personal_info.id) record.save() ''' 以下是自动生成健康档案编号的方法,但是需求手动设置健康档案编号 if resident.village: village = resident.village village.ehr_no += 1 resident.ehr_no = village.id + '%05d' % village.ehr_no village.save() else: resident.ehr_no = '13108200000000000' ''' if resident.ehr_no is None: ehr_village_no = int(request.POST.get( 'ehr_village_no')) # 由于是必填项,而且是数字类型,所以在此不必检查类型 ehr_unique_no = int( request.POST.get('ehr_unique_no')) # 由于是必填项,而且是数字类型,所以在此不必检查类型 town_no = request.user.userprofile.clinic.town_clinic.region.id resident.ehr_no = town_no + '%03d' % ehr_village_no + '%05d' % ehr_unique_no resident.save() if resident.identity is None and personal_info.identity is not None: resident.identity = personal_info.identity resident.save() elif resident.identity is not None and personal_info.identity is not None: if resident.identity != personal_info.identity: resident.identity = personal_info.identity resident.save() if resident.mobile is None and personal_info.phone is not None: resident.mobile = personal_info.phone resident.save() elif resident.mobile is not None and personal_info.phone is not None: if resident.mobile != personal_info.phone: resident.mobile = personal_info.phone resident.save() success = True else: success = False return json_result({'success': success, 'resident_id': resident.id})