Exemplo n.º 1
0
def personal_info_edit_submit(request):
    resident_id = request.POST.get('resident_id')
    if resident_id:
        resident_id = int(resident_id)
        resident = Resident.objects.get(id=resident_id)
        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')
        resident.name = request.POST.get('resident_name')
        resident.gender = gender
        resident.nation = nation
        resident.birthday = request.POST.get('birthday')
        resident.address = request.POST.get('address')
        resident.identity = request.POST.get('identity')
        resident.mobile = request.POST.get('phone')
        resident.update_by = request.user

        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()

        form = PersonalInfoForm(request.POST)
        if form.is_valid():
            debug.info(resident.personal_info_table.id)
            debug.info(form.is_valid())
            debug.info(form.cleaned_data)
            submit_data = {
                field: value
                for field, value in form.cleaned_data.items() if value
            }
            result, created = PersonalInfo.objects.update_or_create(
                id=resident.personal_info_table.id, defaults=submit_data)
            resident.save()
            record = WorkRecord.objects.get(
                resident=resident, service_item_alias='personal_info_table')
            record.update_by = request.user
            record.save()
            success = True
        else:
            debug.info(form.errors.as_data())
            success = False
    else:
        success = False

    return json_result({'success': success, 'resident_id': resident_id})
Exemplo n.º 2
0
def personal_info_edit_submit(request):
    resident_id = request.POST.get('resident_id')
    if resident_id:
        resident_id = int(resident_id)
        resident = Resident.objects.get(id=resident_id)
        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')
        resident.name = request.POST.get('resident_name')
        resident.gender = gender
        resident.nation = nation
        resident.birthday = request.POST.get('birthday')
        resident.address = request.POST.get('address')
        resident.identity = request.POST.get('identity')
        resident.mobile = request.POST.get('phone')
        resident.update_by = request.user

        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()

        form = PersonalInfoForm(request.POST)
        if form.is_valid():
            debug.info(resident.personal_info_table.id)
            debug.info(form.is_valid())
            debug.info(form.cleaned_data)
            submit_data = {field: value for field, value in form.cleaned_data.items() if value}
            result, created = PersonalInfo.objects.update_or_create(id=resident.personal_info_table.id,
                                                                    defaults=submit_data)
            resident.save()
            record = WorkRecord.objects.get(resident=resident, service_item_alias='personal_info_table')
            record.update_by = request.user
            record.save()
            success = True
        else:
            debug.info(form.errors.as_data())
            success = False
    else:
        success = False

    return json_result({'success': success, 'resident_id': resident_id})
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
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})