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 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
def index(request): """ Renders a request object and loads up the index page. :param request: Accepts a request object. :return: An index.html is rendered showing the homepage and provided links. """ #creates the groups if they do not exist if not Group.objects.filter(name="Administrator").exists(): Group.objects.create(name="Administrator") if not Group.objects.filter(name="Doctor").exists(): Group.objects.create(name="Doctor") if not Group.objects.filter(name="Patient").exists(): Group.objects.create(name="Patient") if not Group.objects.filter(name="Nurse").exists(): Group.objects.create(name="Nurse") if Hospital.objects.count() == 0: h = Hospital(name="Chesnut Hill Hospital") h.save() h = Hospital(name="Pennsylvania Central Hospital") h.save() #adds default admin on the site, when db is cleaned if User.objects.filter(groups__name='Administrator').count() == 0: user = User.objects.create_user(username="******", email="*****@*****.**", password="******", first_name='admin', last_name='admin') user.save() staff = StaffProfile( user=user, hospital=Hospital.objects.get(name="Chesnut Hill Hospital"), previous_employment="Somewhere", education_information="None what so ever", accreditation="Nothing") staff.save() #adds the admin to the group user.groups.add(Group.objects.filter(name="Administrator")[0]) user.save() if request.user.is_authenticated(): user = request.user user_group = user.groups.all()[0].name if user_group == "Administrator": user_group = "admin" return HttpResponseRedirect("/healthnet/" + user_group.lower() + "/") return render(request, "healthnet/index.html")