def form_valid(self, form): username = form.cleaned_data['username'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] date_of_birth = form.cleaned_data['date_of_birth'] type = form.cleaned_data['type'] hospital = form.cleaned_data['hospital'] user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() if type == 'doctor': staff = Doctor.objects.create(user=user) staff.hospitals.add(hospital) elif type == 'nurse': staff = Nurse.objects.create(user=user, hospital=hospital) staff.save() customLog.add_log( "New %s named %s registered to HealthNet" % (type, username), 'REGIST') return super(StaffRegisterView, self).form_valid(form)
def form_valid(self, form): self.patient.admitted_hospital = form.cleaned_data['admitted_hospital'] self.patient.save() # saves changes customLog.add_log("%s transferred %s to %s" % (self.request.user.username, self.patient, self.patient.admitted_hospital), 'TRANSFR') # logs changes return super(TransferPatientView, self).form_valid(form)
def form_valid(self, form): self.test.testComment = form.cleaned_data['test_comment'] self.test.testImage = form.cleaned_data['test_image'] self.test.save() customLog.add_log( "User %s test edited" % (self.test.testPatient.user.username), 'TESTED') return super(TestEditView, self).form_valid(form)
def form_valid(self, form): self.patient.medical_conditions = form.cleaned_data[ 'medical_conditions'] self.patient.save() # saves changes customLog.add_log("%s edited %s medical info" % (self.request.user.username, self.patient), 'EDIT') # logs changes return super(PatientView, self).form_valid(form)
def delete(self, request, *args, **kwargs): if hasattr(self.request.user, 'nurse') or hasattr( self.request.user, 'patient'): raise PermissionDenied else: customLog.add_log( "%s deleted Test with ID %s" % (self.request.user.username, self.kwargs['pk']), 'TESTDL') return super(DeleteTest, self).delete(request, *args, **kwargs)
def form_valid(self, form): if form.cleaned_data['confirm']: hospital = self.patient.admitted_hospital self.patient.admitted_hospital = None self.patient.save() # saves changes customLog.add_log( "%s discharged %s from %s" % (self.request.user.username, self.patient, hospital), 'DISCHRG') # logs changes return super(DischargePatientView, self).form_valid(form)
def form_valid(self, form): user = self.request.user if hasattr(user, 'patient'): event = CalendarEvent.objects.create(patient=user.patient, doctor=form.cleaned_data['doctor'], hospital=form.cleaned_data['hospital'], title=form.cleaned_data['description'], start=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']), end=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time'])+ timedelta(hours=1)) message = Message.objects.create() message.sender = user message.recipient = event.doctor.user message.subject = 'New Appointment' message.body = event.patient.get_name() + " has made an appointment, view and confirm from your calendar" message.moderation_status = 'a' event.save() message.save() elif hasattr(user, 'doctor'): event = CalendarEvent.objects.create(patient=form.cleaned_data['patient'], doctor=user.doctor, hospital=form.cleaned_data['hospital'], title=form.cleaned_data['description'], start=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']), end=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time'])+ timedelta(hours=1)) message = Message.objects.create() message.sender = user message.recipient = event.patient.user message.subject = 'New Appointment' message.body = event.doctor.get_name() + " has made an appointment for you, view from your calendar" message.moderation_status = 'a' event.save() message.save() elif hasattr(user, 'nurse'): event = CalendarEvent.objects.create(patient=user.cleaned_data['patient'], doctor=form.cleaned_data['doctor'], hospital=form.cleaned_data['hospital'], title=form.cleaned_data['description'], start=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']), end=datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time'])+ timedelta(hours=1)) event.save() customLog.add_log("%s created an appointment" % user.username, 'APPOINC') return super(CreateAppointmentView, self).form_valid(form)
def form_valid(self, form): username = form.cleaned_data['username'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] date_of_birth = form.cleaned_data['date_of_birth'] address_line1 = form.cleaned_data['address1'] address_line2 = form.cleaned_data['address2'] address_city = form.cleaned_data['city'] address_region = form.cleaned_data['region'] address_zip = form.cleaned_data['zip'] address_country = form.cleaned_data['country'] insurance_company = form.cleaned_data['insurance_company'] insurance_number = form.cleaned_data['insurance_number'] medical_conditions = form.cleaned_data['medical_conditions'] preferred_hospital = form.cleaned_data['preferred_hospital'] emergency_contact = form.cleaned_data['emergency_contact_name'] emergency_contact_number = form.cleaned_data['emergency_phone_number'] user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() patient = Patient.objects.create( user=user, address_line1=address_line1, address_line2=address_line2, address_city=address_city, address_region=address_region, address_zip=address_zip, address_country=address_country, date_of_birth=date_of_birth, insurance_company=insurance_company, insurance_number=insurance_number, medical_conditions=medical_conditions, preferred_hospital=preferred_hospital, emergency_contact=emergency_contact, emergency_contact_number=emergency_contact_number, ) patient.save() customLog.add_log("New patient %s registered to HealthNet" % username, 'REGIST') return super(RegisterView, self).form_valid(form)
def form_valid(self, form): user = self.request.user if hasattr(user, 'patient'): event = self.get_event() event.patient = user.patient event.doctor = form.cleaned_data['doctor'] event.hospital = form.cleaned_data['hospital'] event.title = form.cleaned_data['description'] event.start = datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']) event.verified = False message = Message.objects.create() message.sender = user message.recipient = event.doctor.user message.subject = 'Edited Appointment' message.body = event.patient.get_name() + " has edited an appointment, view and confirm from your calendar" message.moderation_status = 'a' event.save() message.save() elif hasattr(user, 'doctor'): event = self.get_event() event.patient = form.cleaned_data['patient'] event.doctor = user.doctor event.hospital = form.cleaned_data['hospital'] event.title = form.cleaned_data['description'] event.start = datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']) message = Message.objects.create() message.sender = user message.recipient = event.patient.user message.subject = 'Edited Appointment' message.body = event.doctor.get_name() + " has edited an appointment for you, view from your calendar" message.moderation_status = 'a' event.save() message.save() elif hasattr(user, 'nurse'): event = self.get_event() event.patient = form.cleaned_data['patient'] event.doctor = form.cleaned_data['doctor'] event.hospital = form.cleaned_data['hospital'] event.title = form.cleaned_data['description'] event.start = datetime.combine(form.cleaned_data['start_date'], form.cleaned_data['start_time']) event.save() customLog.add_log("%s modified appointment with ID %d" % (user.username, self.get_event().ID), 'APPOINE') return super(AppointmentEdit, self).form_valid(form)
def form_valid(self, form): test_name = form.cleaned_data['test_name'] test_comment = form.cleaned_data['test_comment'] test_image = form.cleaned_data['test_image'] test_doctor = form.cleaned_data['test_doctor'] test = Test.objects.create( testName=test_name, testPatient=self.patient, testComment=test_comment, testImage=test_image, testDoctor=test_doctor, ) test.save() customLog.add_log( "User %s test added" % (test.testPatient.user.username), 'TESTCR') return super(TestCreateView, self).form_valid(form)
def form_valid(self, form): #patient = form.cleaned_data['patient'] medication_name = form.cleaned_data['medication_name'] medication_directions = form.cleaned_data['medication_directions'] medication_amount = form.cleaned_data['medication_amount'] medication_type = form.cleaned_data['medication_type'] medication_refills = form.cleaned_data['medication_refills'] prescribing_doctor = form.cleaned_data['prescribing_doctor'] prescription = Prescription.objects.create( patient=self.patient, medicationName=medication_name, medicationDirections=medication_directions, medicationAmount=medication_amount, medicationType=medication_type, medicationRefills=medication_refills, prescribingDoctor=prescribing_doctor) prescription.save() customLog.add_log( "User %s prescription added" % (prescription.patient.user.username), 'PRESCRB') return super(WritePrescriptionView, self).form_valid(form)
def form_valid(self, form): user = self.request.user patient = user.patient # fields fill out information for user user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.email = form.cleaned_data['email'] password = form.cleaned_data['password'] user.set_password(password) patient.date_of_birth = form.cleaned_data['date_of_birth'] patient.avatar = form.cleaned_data['avatar'] patient.address_line1 = form.cleaned_data['address1'] patient.address_line2 = form.cleaned_data['address2'] patient.address_city = form.cleaned_data['city'] patient.address_region = form.cleaned_data['region'] patient.address_zip = form.cleaned_data['zip'] patient.address_country = form.cleaned_data['country'] patient.insurance_company = form.cleaned_data['insurance_company'] patient.insurance_number = form.cleaned_data['insurance_number'] patient.medical_conditions = form.cleaned_data['medical_conditions'] patient.preferred_hospital = form.cleaned_data['preferred_hospital'] patient.emergency_contact = form.cleaned_data['emergency_contact_name'] patient.emergency_contact_number = form.cleaned_data[ 'emergency_phone_number'] patient.save() # saves changes user.save() login_user = authenticate( username=user.username, password=password) # logs user back in after save login(self.request, login_user) customLog.add_log("%s edited his profile info" % user.username, 'EDIT') # logs changes return super(ProfileUpdateView, self).form_valid(form)
def delete(self, request, *args, **kwargs): if hasattr(self.request.user, 'nurse'): raise PermissionDenied else: customLog.add_log("%s deleted appointment with ID %s" % (self.request.user.username, self.kwargs['pk']), 'APPOINE') return super(DeleteAppointment, self).delete(request, *args, **kwargs)
def sig_user_logged_in(sender, user, request, **kwargs): customLog.add_log("User logged in: %s at %s" % (user, request.META['REMOTE_ADDR']), 'LOGON')