Пример #1
0
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)
Пример #2
0
def child_add(request):
    child = Resident()
    child.name = request.POST.get('name')
    child.gender = int(request.POST.get('gender'))
    child.nation = request.POST.get('nation')

    birthday = request.POST.get('birthday')
    child.birthday = datetime.strptime(birthday, '%Y-%m-%d')
    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
    child.town = town
    child.village = village

    resident_id = request.session['resident_id']
    resident = Resident.objects.get(id=int(resident_id))

    child.family = resident.family
    child.save()
    return HttpResponse(simplejson.dumps({
        'success': True,
        'message': 'OK'
    }),
                        content_type='text/html; charset=UTF-8')
Пример #3
0
def child_add(request):
    child = Resident()
    child.name = request.POST.get('name')
    child.gender = int(request.POST.get('gender'))
    child.nation = request.POST.get('nation')

    birthday = request.POST.get('birthday')
    child.birthday = datetime.strptime(birthday, '%Y-%m-%d')
    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
    child.town = town
    child.village = village

    resident_id = request.session['resident_id']
    resident = Resident.objects.get(id=int(resident_id))

    child.family = resident.family
    child.save()
    return HttpResponse(simplejson.dumps({'success': True, 'message': 'OK'}),
                        content_type='text/html; charset=UTF-8')
Пример #4
0
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")