Beispiel #1
0
def add_hospital_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': "Add Hospital"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = HospitalForm(request.POST)
        if form.is_valid():
            location = Location(city=form.cleaned_data['city'],
                                zip=form.cleaned_data['zip'],
                                state=form.cleaned_data['state'],
                                address=form.cleaned_data['address'])
            location.save()
            hospital = Hospital(
                name=form.cleaned_data['name'],
                phone=form.cleaned_data['phone'],
                location=location,
            )
            hospital.save()
            form = HospitalForm(
            )  # Clean the form when the page is redisplayed
            template_data['alert_success'] = "Successfully added the hospital!"
    else:
        form = HospitalForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/add_hospital.html', template_data)
Beispiel #2
0
def add_hospital_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': "Add Hospital"}
    )
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = HospitalForm(request.POST)
        if form.is_valid():
            location = Location(
                city=form.cleaned_data['city'],
                zip=form.cleaned_data['zip'],
                state=form.cleaned_data['state'],
                address=form.cleaned_data['address']
            )
            location.save()
            hospital = Hospital(
                name=form.cleaned_data['name'],
                phone=form.cleaned_data['phone'],
                location=location,
            )
            hospital.save()
            form = HospitalForm()  # Clean the form when the page is redisplayed
            template_data['alert_success'] = "Successfully added the hospital!"
    else:
        form = HospitalForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/add_hospital.html', template_data)
def handle_hospital_csv(f):
    """
    Handles a CSV containing Hospital information.
    The first row should contain the following information:
        Name
    with the following lines containing information about zero or more Hospitals.
    :param f: The file containing the CSV
    :return: The # of successes and failures
    """
    success = 0;
    fail = 0;
    is_first = True
    for row in f:
        if is_first:
            is_first = False
            continue    # breaks out of for loop
        line = re.split('[,]', row.decode("utf-8").strip())
        if line[0]:
            hosp = line[0]
            address = line[1]
            city = line[2]
            state = line[3]
            zip = line[4]
            phone = line[5]
            try:
                location = Location(
                    city=city,
                    zip=zip,
                    state=state,
                    address=address
                )
                location.save()
                hospital = Hospital(
                    name=hosp,
                    phone=phone,
                    location=location,
                )
                hospital.save()
                success += 1
            except (IntegrityError, ValueError):
                fail += 1
                continue
    return success, fail
Beispiel #4
0
def handle_hospital_csv(f):
    """
    Handles a CSV containing Hospital information.
    The first row should contain the following information:
        Name
    with the following lines containing information about zero or more Hospitals.
    :param f: The file containing the CSV
    :return: The # of successes and failures
    """
    success = 0;
    fail = 0;
    is_first = True
    for row in f:
        if is_first:
            is_first = False
            continue    # breaks out of for loop
        line = re.split('[,]', row.decode("utf-8").strip())
        if line[0]:
            hosp = line[0]
            address = line[1]
            city = line[2]
            state = line[3]
            zip = line[4]
            phone = line[5]
            try:
                location = Location(
                    city=city,
                    zip=zip,
                    state=state,
                    address=address
                )
                location.save()
                hospital = Hospital(
                    name=hosp,
                    phone=phone,
                    location=location,
                )
                hospital.save()
                success += 1
            except (IntegrityError, ValueError):
                fail += 1
                continue
    return success, fail