예제 #1
0
def register_user(email, password, firstname, lastname, role, insurance=""):
    user = User.objects.create_user(email.lower(), email.lower(), password)
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=password,
    )
    profile.save()
    account = Account(role=role, profile=profile, user=user)
    account.save()
    medical_info = MedicalInfo(account=account)
    medical_info.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return user
예제 #2
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    # Get the template data from the session
    template_data = parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data['email'].lower(
                ),  # Username, make sure it's lowercase
                form.cleaned_data['email'],  # Email
                form.cleaned_data['password_first']  # Password
            )
            profile = Profile(
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
                insurance=form.cleaned_data['insurance'],
            )
            profile.save()
            account = Account(role=Account.ACCOUNT_PATIENT,
                              profile=profile,
                              user=user)
            account.save()
            medicalinfo = MedicalInfo(patient=account.user,
                                      alzheimer=False,
                                      asthma=False,
                                      diabetes=False,
                                      stroke=False)
            medicalinfo.save()
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account registered", user)
            logger.log(Action.ACTION_ACCOUNT, "Account login", user)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully registered with HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
예제 #3
0
def register_admit_user(reason, email, firstname, lastname, hospital):
    password = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(8))
    insurance = password
    role = Account.ACCOUNT_PATIENT
    user = User.objects.create_user(email.lower(), email.lower(), password)
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=insurance,
    )
    profile.save()
    account = Account(role=role, profile=profile, user=user)
    account.save()
    medical_info = MedicalInfo(account=account)
    medical_info.save()
    admission = Admission(reason=reason, account=account, hospital=hospital)
    admission.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return admission
예제 #4
0
def createemployee_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = EmployeeRegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data['email'].lower(
                ),  # Username, make sure it's lowercase
                form.cleaned_data['email'],  # Email
                form.cleaned_data['password_first']  # Password
            )
            profile = Profile(
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
            )
            profile.save()
            account = Account(role=form.cleaned_data['employee'],
                              profile=profile,
                              user=user)
            account.save()
            logger.log(Action.ACTION_ADMIN,
                       'Admin registered ' + user.username, request.user)
            form = EmployeeRegisterForm(
            )  # Clean the form when the page is redisplayed
            template_data[
                'alert_success'] = "Successfully created new employee account"
    else:
        form = EmployeeRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/createemployee.html',
                  template_data)
예제 #5
0
def register_user(email, password, firstname, lastname, role, insurance=""):
    user = User.objects.create_user(
        email.lower(),
        email.lower(),
        password
    )
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=insurance,
    )
    profile.save()
    account = Account(
        role=role,
        profile=profile,
        user=user
    )
    account.save()
    medical_info = MedicalInfo(
        account=account
    )
    medical_info.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return user
예제 #6
0
def getAccountRole(user):
    """
    :param user: The user model
    :return: The string representation of the name for the role
    """
    return Account.to_name(user.account.role).lower()
예제 #7
0
def getAccountRole(user):
    """
    :param user: The user model
    :return: The string representation of the name for the role
    """
    return Account.to_name(user.account.role).lower()