def update_information(request, patient_id): current = adapter(request, 'get', 'patients_summary/'+patient_id) form = PatientForm(request.POST or current) context = {'form': form} if request.method == "POST": if form.is_valid(): data = form.cleaned_data adapter(request, 'put', 'patients_summary/'+patient_id, data) return redirect('update-information', patient_id) return render(request, 'actions/update_information.html', context)
def new_appointment(request, patient_id): form = AppointmentForm(request.POST or None) context = {'form': form} if request.method == "POST": if form.is_valid(): data = form.cleaned_data data['patient'] = patient_id try: adapter(request, 'post', 'appointments', data) return redirect('check-in', patient_id) except Exception as err: if '409' in str(err): form.add_error('scheduled_time', 'Timeslot not available') else: form.add_error('scheduled_time', 'Mystery error!') return render(request, 'actions/new_appointment.html', context)
def new_patient(request): form = PatientForm(request.POST or None) context = {'form': form} if request.method == "POST": if form.is_valid(): data = form.cleaned_data patient = adapter(request, 'post', 'patients', data) return redirect('new-appointment', patient['id']) return render(request, 'actions/new_patient.html', context)
def check_in(request, patient_id): # use next appointment from patients resource instead? extra = {'date': datetime.date.today(), 'patient': patient_id} try: appointment = adapter(request, 'get', 'appointments', extra)['results'][0] except IndexError: raise Http404("No appointments today") # unfurl datetime purely for display?? dt, fmt = appointment['scheduled_time'], "%Y-%m-%dT%H:%M:%S" appointment['scheduled_time'] = datetime.datetime.strptime(dt, fmt) form = AppointmentForm(appointment) context = {'form': form} if request.method == "POST": data = form.data data['status'] = "Cancelled" if 'cancel' in request.POST else "Arrived" adapter(request, 'put', 'appointments/'+appointment['id'], form.data) return redirect('check-in', patient_id) return render(request, 'actions/check_in.html', context)
def transactional(request, patient_id=None): ''' very ephemeral login for patient ''' form = TransactionForm(request.POST or None) context = {'form': form} if request.method == "POST": if form.is_valid(): data = form.cleaned_data first, sep, last = data['name'].partition(' ') extra = { 'first_name': first, 'last_name': last, 'date_of_birth': data['date_of_birth'], } try: patient = adapter(request, 'get', 'patients_summary', extra)['results'][0] return redirect(request.GET['next'], patient['id']) except: raise Http404("No patient found matching those credentials") return render(request, 'actions/transactional.html', context)
def json_table(request): extra = {'date': datetime.date.today()} context = adapter(request, 'get', request.GET['q'], extra) return render(request, 'json_table.html', context)
def schedule(request): extra = {'date': datetime.date.today()} context = adapter(request, 'get', 'appointments', extra) return render(request, 'schedule.html', context)