def view_patient(request, pk): """ Doctor view for a specific patient in the system :param request: Accepts a request object. :param pk: Private Key for a user :return: The view in html format for a specific patient """ userProfile = UserProfile.objects.get(id=pk) prescriptions = Prescription.objects.filter(user=userProfile.user) plen = int(prescriptions.count()) tests = Test.objects.filter(user=userProfile.user) tlen = int(tests.count()) if request.method == 'GET': if 'makepscript' in request.GET: return HttpResponseRedirect( '/healthnet/doctor/makeprescription/%s/' % userProfile.id) elif 'maketest' in request.GET: return HttpResponseRedirect('/healthnet/doctor/maketest/%s/' % userProfile.id) elif 'update' in request.GET: userProfileForm = PatientProfileForm(data=request.GET, instance=userProfile) if userProfileForm.is_valid(): userProfileForm.save() userProfile = UserProfile.objects.get(id=pk) elif 'allpatients' in request.GET: return all_patients(request) elif 'admitreleaseform' in request.GET: return admit_release_patient(request, userProfile.id) elif 'transferpatient' in request.GET: return transfer_patient(request, userProfile.id) elif 'uploadfile' in request.GET: return upload_file(request, userProfile.id) userForm = PatientForm(data=model_to_dict(userProfile.user)) userProfileForm = PatientProfileForm(data=model_to_dict(userProfile)) userProfileForm.fields['hospital'].widget = forms.HiddenInput() dp = DoctorProfile.objects.get(user=request.user) dph = dp.hospital.filter(name=userProfile.hospital.name) if dph.exists() and dp.hospital.count() < 2: temp = False else: temp = True context = { "userprofile": userProfile, "userprofileform": userProfileForm, "pscripts": prescriptions, "tests": tests, "plen": plen, "tlen": tlen, "cantransfer": temp, "files": PatientFile.objects.filter(user=userProfile.user), } return render(request, 'doctor/doctor_view_patient.html', context)
def view_patient_view(request, pk): required_patient = get_object_or_404(Patient, pk=pk) patient_form = PatientForm(form_type='view', instance=required_patient) patient_attachments = Patient_Files.objects.filter(patient=pk) required_patient_past_med = Past_Medical_History.objects.filter( patient=pk).first() patient_past_med = Past_Medical_History_Form( form_type='view', instance=required_patient_past_med) # patient_attachments = Patient_Files_formset(instance=required_patient) exit_form = Patient_Exit_Form() if request.method == 'POST': exit_form = Patient_Exit_Form(request.POST) if exit_form.is_valid(): exit_obj = exit_form.save(commit=False) exit_obj.patient = required_patient exit_obj.created_by = request.user exit_obj.last_update_by = request.user exit_obj.save() return redirect('patient:view-patient', pk=pk) createContext = { 'page_title': _('FOLLOW UP MAIN PAGE'), 'patient_id': pk, 'patient_form': patient_form, 'patient_attachments': patient_attachments, 'patient_past_med': patient_past_med, 'media_url': settings.MEDIA_URL, 'exit_form': exit_form, 'required_patient': required_patient } return render(request, 'view-patient.html', createContext)
def create_new_patient(request): ''' POST request with multipart form to create a new patient :param request: POST request with the required parameters. Date parameters are accepted in the format 1995-03-30. :return: Http Response with corresponding status code ''' try: form = PatientForm(request.POST, request.FILES) if form.is_valid(): patient = form.save(commit=False) patient.save() response = serializers.serialize("json", [ patient, ]) return HttpResponse(response, content_type="application/json") else: return JsonResponse(form.errors, status=400) except DataError as e: return JsonResponse({"message": str(e)}, status=400)
def view_patient(request, pk): """ Nurse will be able to view a specific patient medical information :param request: Accepts a request object :return: The medical information for a specific user """ userProfile = UserProfile.objects.get(id=pk) prescriptions = Prescription.objects.filter(user=userProfile.user) plen = int(prescriptions.count()) tests = Test.objects.filter(user=userProfile.user) tlen = int(tests.count()) if request.method == 'GET': if 'makepscript' in request.GET: return HttpResponseRedirect( '/healthnet/nurse/makeprescription/%s/' % userProfile.id) elif 'maketest' in request.GET: return HttpResponseRedirect('/healthnet/nurse/maketest/%s/' % userProfile.id) elif 'update' in request.GET: userProfileForm = PatientProfileForm(data=request.GET, instance=userProfile) if userProfileForm.is_valid(): userProfileForm.save() userProfile = UserProfile.objects.get(id=pk) elif 'allpatients' in request.GET: return all_patients(request) elif 'admitreleaseform' in request.GET: return admit_release_patient(request, userProfile.id) elif 'transferpatient' in request.GET: return transfer_patient(request, userProfile.id) elif 'viewappointments' in request.GET: return HttpResponseRedirect( "/healthnet/nurse/viewpatientappointment/%s/" % userProfile.pk) elif 'home' in request.GET: return HttpResponseRedirect("/healthnet/nurse/") userForm = PatientForm(data=model_to_dict(userProfile.user)) userProfileForm = PatientProfileForm(data=model_to_dict(userProfile)) userProfileForm.fields['hospital'].widget = forms.HiddenInput() context = { "userprofile": userProfile, "userprofileform": userProfileForm, "pscripts": prescriptions, "tests": tests, "plen": plen, "tlen": tlen, "files": PatientFile.objects.filter(user=userProfile.user), } return render(request, 'nurse/nurse_view_patient.html', context)
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) patient_form = PatientForm(data=request.POST) user = user_form.save(commit=False) user.set_password(user.password) patient = patient_form.save(commit=False) user.username = patient.nationalId user.save() patient.user = user patient.save() return HttpResponseRedirect('/main_Side/Welcome_to_Salamat/') else: user_form = UserForm() patient_form = PatientForm() return render(request, 'patient/register-login.html', { 'user_form': user_form, 'patient_form': patient_form })
def add_patient(request): if request.method == "GET": form = PatientForm() return render(request, "patient_registration.html", {'form': form}) else: form = PatientForm(request.POST) if form.is_valid(): form.save() return redirect("/receptionist")
def update(request, id): patients = Patient.objects.get(patient_id=id) if request.method == "POST": form = PatientForm(request.POST, instance=patients) form.save() return redirect("/patient") else: form = PatientForm(instance=patients) return render(request, "patient/edit.html", {'form': form})
def createPatient(request): if request.method == 'POST': patient_form = PatientForm(request.POST) if patient_form.is_valid(): patient_form.save() return HttpResponseRedirect(reverse('dashboard')) else: return render(request, 'receptionist/create_patient.html', {'patientform': patient_form}) else: patient_form = PatientForm() return render(request, 'receptionist/create_patient.html', {'patient_form': patient_form})
def update_patient(request, pk): print(pk) update_object=get_object_or_404(Patient,pk=pk) print(update_object) patient_form=PatientForm(instance=update_object) if(request.method=='POST'): patient_form=PatientForm(request.POST or None, instance=update_object) if patient_form.is_valid(): patient_form.save() return redirect('patient_home') return render(request, 'patient/patient_form.html', { "form" : patient_form })
def save(request): print("print") print(request.POST) if request.method == "POST": print(request.POST) form = PatientForm(request.POST) form.save() return redirect('/patient') else: form = PatientForm() return render(request, "patient/create.html", {'form': form})
def update_profile(request): patient = Patient.objects.get(user=request.user) photo = patient.picture if request.method == 'POST': form = PatientForm(request.POST, request.FILES, instance=patient) if form.is_valid(): form.save() messages.success(request, 'Profile updated!') return redirect('update_profile') else: form = PatientForm(instance=patient) context = {'form': form, 'photo': photo} return render(request, 'update_profile.html', context)
def signup(request): if request.method == 'POST': form = ExtendedUserCreationForm(request.POST) patient_form = PatientForm(request.POST) if form.is_valid() and patient_form.is_valid(): user = form.save() patient = patient_form.save(commit=False) patient.user = user patient.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(username=username, password=password) login(request, user) return redirect('home') else: form = ExtendedUserCreationForm() patient_form = PatientForm() context = {'form': form, 'patient_form': patient_form} return render(request, 'accounts/signup.html', context)
def create_patient_view(request): patient_form = PatientForm(form_type='create', ) patient_attachments = Patient_Files_formset() patient_gynecology = Patient_Gynecology_formset() patient_past_med = Past_Medical_History_Form(form_type='create', ) if request.method == 'POST': patient_form = PatientForm(request.POST, form_type='create') patient_attachments = Patient_Files_formset(request.POST, request.FILES) patient_gynecology = Patient_Gynecology_formset(request.POST) patient_past_med = Past_Medical_History_Form(request.POST, form_type='create') if patient_form.is_valid() and patient_attachments.is_valid( ) and patient_gynecology.is_valid() and patient_past_med.is_valid(): master_obj = patient_form.save(commit=False) master_obj.hospital_id = request.user.clinic_id master_obj.barcode = master_obj.insurance_number master_obj.created_by = request.user master_obj.last_update_by = request.user master_obj.save() patient_gynecology = Patient_Gynecology_formset( request.POST, instance=master_obj) if patient_gynecology.is_valid(): patient_gynecology_form = patient_gynecology.save(commit=False) for patient_gyno_obj in patient_gynecology_form: patient_gyno_obj.created_by = request.user patient_gyno_obj.last_update_by = request.user patient_gyno_obj.save() patient_attachments = Patient_Files_formset(request.POST, request.FILES, instance=master_obj) detail_obj = patient_attachments.save(commit=False) for x in detail_obj: x.created_by = request.user x.last_update_by = request.user x.save() past_med_obj = patient_past_med.save(commit=False) past_med_obj.patient = master_obj past_med_obj.created_by = request.user past_med_obj.last_update_by = request.user past_med_obj.save() if master_obj.patient_type == 'DELIVER': messages.success(request, 'تم الحفظ بنجاح') return redirect('patient:all-delivery', pk=master_obj.id) elif master_obj.patient_type == 'OPERATION': messages.success(request, 'تم الحفظ بنجاح') return redirect('surgery:create-patient-surgery', patient_id=master_obj.id) else: messages.success(request, 'تم الحفظ بنجاح') return redirect('patient:all-checkup', patient_id=master_obj.id) else: if patient_form.errors: messages.error(request, patient_form.errors) elif patient_attachments.errors: for error in patient_attachments.errors: messages.error(request, error) elif patient_past_med.errors: messages.error(request, patient_past_med.errors) createContext = { 'page_title': _('ADD NEW PATIENT'), 'patient_form': patient_form, 'patient_attachments': patient_attachments, 'patient_gynecology': patient_gynecology, 'patient_past_med': patient_past_med, } return render(request, 'create-patient.html', createContext)
def update_patient_view(request, pk): required_patient = Patient.objects.get(pk=pk) patient_form = PatientForm(form_type='update', instance=required_patient) required_patient_past_med = Past_Medical_History.objects.filter( patient=pk).first() patient_gynecology = Patient_Gynecology_formset(instance=required_patient) patient_past_med = Past_Medical_History_Form( form_type='update', instance=required_patient_past_med) patient_attachments = Patient_Files_formset(instance=required_patient) if request.method == 'POST': patient_form = PatientForm(request.POST, form_type='update', instance=required_patient) patient_past_med = Past_Medical_History_Form(request.POST, form_type='update', instance=required_patient) patient_gynecology = Patient_Gynecology_formset( request.POST, instance=required_patient) patient_attachments = Patient_Files_formset(request.POST, request.FILES, instance=required_patient) if patient_form.is_valid() and patient_attachments.is_valid( ) and patient_past_med.is_valid(): master_obj = patient_form.save(commit=False) master_obj.created_by = request.user master_obj.barcode = master_obj.insurance_number master_obj.last_update_by = request.user master_obj.save() patient_gynecology = Patient_Gynecology_formset( request.POST, instance=master_obj) if patient_gynecology.is_valid(): patient_gynecology_form = patient_gynecology.save(commit=False) for patient_gyno_obj in patient_gynecology_form: patient_gyno_obj.created_by = request.user patient_gyno_obj.last_update_by = request.user patient_gyno_obj.save() patient_attachments = Patient_Files_formset(request.POST, request.FILES, instance=master_obj) detail_obj = patient_attachments.save(commit=False) for x in detail_obj: x.created_by = request.user x.last_update_by = request.user x.save() past_med_obj = patient_past_med.save(commit=False) past_med_obj.patient = master_obj past_med_obj.created_by = request.user past_med_obj.last_update_by = request.user past_med_obj.save() messages.success(request, 'تم الحفظ بنجاح') return redirect('patient:view-patient', pk=master_obj.id) else: print(patient_form.errors) messages.error(request, patient_form.errors) messages.error(request, patient_past_med.errors) for error in patient_attachments.errors: messages.error(request, error) createContext = { 'page_title': _('EDIT PATIENT {}').format(required_patient), 'patient_form': patient_form, 'patient_past_med': patient_past_med, 'patient_gynecology': patient_gynecology, 'patient_id': pk, 'patient_attachments': patient_attachments, } return render(request, 'create-patient.html', createContext)