Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################
- ####### views.py
- import os
- import pyqrcode
- from pyzbar.pyzbar import decode
- from PIL import Image
- def save_patient(request):
- """ Collecting data for patients and save patient data to database """
- if request.method == 'POST':
- form = PatientsForm(request.POST or None, request.FILES or None)
- if form.is_valid():
- barcode_value = request.POST.get('barurl')
- if barcode_value == None or barcode_value == '':
- messages.success(request, 'Create barcode without value is not valid')
- elif barcode_value != None:
- qr = pyqrcode.create(barcode_value)
- name = request.POST.get('name')
- split_name = name.split()
- img_name = '-'.join(split_name)
- file_path = 'media_root/patients/' + str(img_name) + '.png'
- # print(img_name)
- match = Patients.objects.filter(name=name).exists()
- if not os.path.exists(file_path) and not match:
- qr.png('media_root/patients/' + str(img_name) + '.png', scale=8)
- save_form = form.save(commit=False)
- save_form.barimg = 'patients/' + str(img_name) + '.png'
- save_form.barurl = barcode_value
- save_form.save()
- pat_id = save_form.id
- Visits.objects.create(patient_id=pat_id, visitdate=date.today(),
- complain="any comp", sign="any sign",
- amount=0, intervention="any intervention")
- messages.success(request, 'Saving process done ... ')
- return redirect('patientdata:table_patient')
- else:
- messages.error(request, 'Barcode is already exists or Patient name is repeated')
- return redirect(reverse('patientdata:save_patient'))
- else:
- form = PatientsForm()
- lastid = Patients.objects.values('id').last()
- if lastid is not None:
- patid = lastid['id'] + 1
- else:
- patid = 1
- # print(patid)
- label2 = "Save"
- context = {
- 'savepatform': form,
- 'lastid': patid,
- # 'button_lable': label,
- 'lable2': label2,
- }
- return render(request, 'patientdata/save_patient.html', context)
- ######################################
- ###### save_patient.html
- <form method="POST" enctype="multipart/form-data">{% csrf_token %}
- <div class="float-left" id="left-savepat-div" style="overflow-x: auto; width: 45%; height: 100%;">
- <!-- {{savepatform.id.label_tag}} {{savepatform.id}} <br> -->
- {{savepatform.name.label_tag}}
- {% render_field savepatform.name v-model="name" %} <br>
- <!-- -->
- {{savepatform.address.label_tag}} {{savepatform.address}}
- <br>
- <!-- -->
- {{savepatform.birth_date.label_tag}}
- {% render_field savepatform.birth_date v-model="dob" id="dob" %}
- <br>
- {{savepatform.age.label_tag}}
- {% render_field savepatform.age ::value="getAge" id="age" %}
- <br>
- <hr>
- <button type="submit" class="btn btn-dark" id="savepatform-btn">
- {{lable2}}
- </button>
- </div>
- <div class="float-right" id="right-savepat-div" style="overflow-x: auto; width: 45%; height: 100%;">
- {{savepatform.cardid.label_tag}}
- {% render_field savepatform.cardid v-model="cardid" %} <br>
- {{savepatform.phone.label_tag}} {{savepatform.phone}} <br>
- {{savepatform.mobile.label_tag}} {{savepatform.mobile}} <br>
- {{savepatform.barcode.label_tag}}
- {% render_field savepatform.barcode ::value="this.id + this.sign + this.dob + this.sign + this.cardid" %}
- <br>
- <!-- {{savepatform.barimg.label_tag}} -->
- <!-- {% render_field savepatform.barimg %} -->
- {% render_field savepatform.barurl ::value="this.url + this.id + this.sign + this.dob + this.sign + this.cardid" hidden="true" %}
- <!-- <img class="image" src="{{ Patients.barimg.url }}"> -->
- <hr>
- </div>
- </form>
- {% block scripts %}
- <script>
- // Using Vue.js Here
- var savePatient = new Vue ({
- el: '#savePatient',
- delimiters: ['[[', ']]'],
- data: {
- patient_name: '' ,
- title: "Add New Patient",
- message: '{{ non_field_errors }}' ,
- id:'{{ lastid }}', // from views
- name:'',
- cardid:'',
- dob: new Date(),
- age: '',
- url:'http://192.168.1.120:8000/pat.../patient/details/by/barcode/',
- barcode:'',
- sign:'_',
- },
- </script>
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement