Пример #1
0
def assignmed_select(request):
    if request.user.profile.role == 'GRDN':
        children = [("", "-----------")]
        h = requests.get(rest_prefix + "ibm.wsc.immunichain.Childform",
                         verify=False)
        h = h.json()
        r = list(
            filter(
                lambda d: d['guardian'] ==
                (guardian_prefix + request.user.username), h))
        for child in r:
            children.append(
                (child['cid'], child['name'] + ", " + child['cid']))
        if request.method == 'POST':
            form = NameForm(children, request.POST)
            if form.is_valid():
                cid = form.cleaned_data.get('child_access')
                chosen = (item for item in r if item["cid"] == cid).next()
                child_name = chosen["name"]
                r = requests.get(rest_prefix +
                                 "ibm.wsc.immunichain.MedProvider",
                                 verify=False)
                avail_medproviders = [(d['name'], d['medid'])
                                      for d in r.json()]
                renderdict = {
                    'cid': cid,
                    'child_name': child_name,
                    'avail_medproviders': avail_medproviders
                }
                return render(request, 'assignmed_select.html', renderdict)
        else:
            form = NameForm(children)
        return render(request, 'assignmed_select.html', {'form': form})
    else:
        return redirect('deny')
Пример #2
0
def django_form(request):
    form = NameForm(request.POST or None)

    name = ''
    birth_year = ''
    favorite_colors = ''

    if request.method == 'POST':
        if form.is_valid():
            name = form.cleaned_data['name']
            birth_year = form.cleaned_data['birth_year']
            favorite_colors = form.cleaned_data['favorite_colors']

            import pdb
            pdb.set_trace()
    return render(request, 'core/django-form.html', {
        'form': form,
        'name': name
    })
Пример #3
0
def reassign_select(request):
    if request.user.profile.role == 'GRDN':
        children = [("", "-----------")]
        h = requests.get(rest_prefix + "ibm.wsc.immunichain.Childform",
                         verify=False)
        h = h.json()
        r = list(
            filter(
                lambda d: d['guardian'] ==
                (guardian_prefix + request.user.username), h))
        for child in r:
            children.append(
                (child['cid'], child['name'] + ", " + child['cid']))
        if request.method == 'POST':
            form = NameForm(children, request.POST)
            if form.is_valid():
                cid = form.cleaned_data.get('child_access')
                chosen = (item for item in r if item["cid"] == cid).next()
                #check if the child is old enough
                dob = chosen["dob"]
                dobcheck = datetime.strptime(dob, '%Y-%m-%d')
                timenow = datetime.now()
                difference = timenow - dobcheck
                difference_in_years = (difference.days +
                                       difference.seconds / 86400) / 365.0
                if difference_in_years >= LEGAL_AGE:
                    child_name = chosen["name"]
                    newform = SignUpForm_reassign()
                    renderdict = {
                        'cid': cid,
                        'child_name': child_name,
                        'newform': newform
                    }
                    return render(request, 'reassign_select.html', renderdict)
                else:
                    return redirect('underage')
        else:
            form = NameForm(children)
        return render(request, 'reassign_select.html', {'form': form})
    else:
        return redirect('deny')
Пример #4
0
def deauth_member_select(request):
    if request.user.profile.role == 'GRDN':
        children = [("", "-----------")]
        h = requests.get(rest_prefix + "ibm.wsc.immunichain.Childform",
                         verify=False)
        h = h.json()
        r = list(
            filter(
                lambda d: d['guardian'] ==
                (guardian_prefix + request.user.username), h))
        for child in r:
            children.append(
                (child['cid'], child['name'] + ", " + child['cid']))
        if request.method == 'POST':
            form = NameForm(children, request.POST)
            if form.is_valid():
                cid = form.cleaned_data.get('child_access')
                chosen = (item for item in r if item["cid"] == cid).next()
                child_name = chosen["name"]
                current_members = chosen["members"]
                cleaned = [
                    s.replace(memberorg_prefix, '') for s in current_members
                ]
                avail_members = []
                for memberid in cleaned:
                    user = requests.get(
                        rest_prefix + "ibm.wsc.immunichain.Member/" + memberid,
                        verify=False)
                    user = user.json()
                    avail_members.append((user['name'], memberid))
                renderdict = {
                    'cid': cid,
                    'child_name': child_name,
                    'avail_members': avail_members
                }
                return render(request, 'deauth_member_select.html', renderdict)
        else:
            form = NameForm(children)
        return render(request, 'deauth_member_select.html', {'form': form})
    else:
        return redirect('deny')
Пример #5
0
def addImmunizations(request):
    if request.user.profile.role == 'HEAL':
        children = [("", "-----------")]
        h = requests.get(rest_prefix + "ibm.wsc.immunichain.Childform",
                         verify=False)
        h = h.json()
        r = list(
            filter(
                lambda d: (mprovider_prefix + request.user.username) in d[
                    'medproviders'], h))
        for child in r:
            children.append(
                (child['cid'], child['name'] + ', ' + child['cid']))
        form = NameForm(children)
        return render(request, 'addImmunizations.html', {'form': form})
    else:
        return redirect('deny')
Пример #6
0
def viewchild(request):
    user_role = request.user.profile.role
    username = request.user.username
    r = requests.get(rest_prefix + "ibm.wsc.immunichain.Childform",
                     verify=False)
    CHILD_CHOICES = [("", "-----------")]
    for child in r.json():
        if user_role == 'GRDN':
            if ("resource:ibm.wsc.immunichain.Guardian#" +
                    username) == child['guardian']:
                CHILD_CHOICES.append(
                    (child['cid'], child['name'] + ", " + child['cid']))
        elif user_role == 'MEMB':
            if (memberorg_prefix + username) in child['members']:
                CHILD_CHOICES.append(
                    (child['cid'], child['name'] + ", " + child['cid']))
        else:
            if (mprovider_prefix + username) in child['medproviders']:
                CHILD_CHOICES.append(
                    (child['cid'], child['name'] + ", " + child['cid']))

    if request.method == 'POST':
        form = NameForm(CHILD_CHOICES, request.POST)
        if form.is_valid():
            cid = form.cleaned_data.get('child_access')
            h = (item for item in r.json() if item["cid"] == cid).next()
            userdict = {}
            providers = h["medproviders"]
            members = h["members"]
            vaccines = h["immunizations"]
            guardian = h["guardian"]
            for provider in providers:
                if provider not in userdict.keys():
                    garbage, lookup = provider.split("#", 1)
                    r = requests.get(rest_prefix +
                                     "ibm.wsc.immunichain.MedProvider/" +
                                     lookup,
                                     verify=False)
                    r = r.json()
                    userdict[provider] = r["name"]
            for member in members:
                if member not in userdict.keys():
                    garbage, lookup = member.split("#", 1)
                    r = requests.get(rest_prefix +
                                     "ibm.wsc.immunichain.Member/" + lookup,
                                     verify=False)
                    r = r.json()
                    userdict[member] = r["name"]
            if guardian not in userdict.keys():
                garbage, lookup = guardian.split("#", 1)
                r = requests.get(rest_prefix +
                                 "ibm.wsc.immunichain.Guardian/" + lookup,
                                 verify=False)
                r = r.json()
                userdict[guardian] = r["name"]
            for record in vaccines:
                if record['provider'] not in userdict.keys(
                ) and record['provider'] != 'default':
                    r = requests.get(rest_prefix +
                                     "ibm.wsc.immunichain.MedProvider/" +
                                     record['provider'],
                                     verify=False)
                    r = r.json()
                    userdict[record['provider']] = r["name"]

            return render(request, 'viewchild.html', {
                'h': h,
                'form': form,
                "userdict": userdict
            })
    else:
        form = NameForm(CHILD_CHOICES)

    return render(request, 'viewchild.html', {'form': form})