diff --git a/.gitignore b/.gitignore
index 3ee07a17..7aba47d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
-class HealthProfessional(models.Model, User)
*.pyc
__pycache__
virtual/
.vscode/
+.idea/
db.sqlite3
.DS_Store
.coverage
diff --git a/medical_prescription/chat/models/response.py b/medical_prescription/chat/models/response.py
index c95c9836..ea4fd395 100644
--- a/medical_prescription/chat/models/response.py
+++ b/medical_prescription/chat/models/response.py
@@ -1,7 +1,9 @@
import os
+# Django
from django.db import models
+# Django Local
from chat import constants
from user.models import User
from .pathfile import UploadToPathAndRename
diff --git a/medical_prescription/prescription/admin.py b/medical_prescription/prescription/admin.py
index f0c98670..b92876f8 100644
--- a/medical_prescription/prescription/admin.py
+++ b/medical_prescription/prescription/admin.py
@@ -10,7 +10,8 @@
PrescriptionRecommendation,
NoPatientPrescription,
PatientPrescription,
- Recommendation
+ Recommendation,
+ Pattern
)
admin.site.register(Prescription)
@@ -22,3 +23,4 @@
admin.site.register(PatientPrescription)
admin.site.register(NoPatientPrescription)
admin.site.register(Recommendation)
+admin.site.register(Pattern)
diff --git a/medical_prescription/prescription/constants.py b/medical_prescription/prescription/constants.py
index 28db316d..4a0a8873 100644
--- a/medical_prescription/prescription/constants.py
+++ b/medical_prescription/prescription/constants.py
@@ -41,3 +41,25 @@
# Empty constants
EMPTY = 0
+
+# Constants for print prescription
+MAX_LENGTH_CLINIC = 150
+MAX_LENGTH_HEADER = 150
+MAX_LENGTH_FOOTER = 150
+MAX_LENGTH_NAME = 50
+
+# Fonts fields
+TIMES_ROMAN = 'Times-Roman'
+HELVETICA = 'Helvetica'
+ARIAL = 'Arial'
+COURIER = 'Courier'
+
+FONT_CHOICE = ((TIMES_ROMAN, 'Times-Roman'), (HELVETICA, 'Helvetica'), (ARIAL, 'Arial'), (COURIER, 'Courier'))
+
+# Fonts size fields
+NINE = '9'
+TEN = '10'
+TWELVE = '12'
+FOURTEEN = '14'
+
+FONT_SIZE_CHOICE = ((NINE, '9'), (TEN, '10'), (TWELVE, '12'), (FOURTEEN, '14'))
diff --git a/medical_prescription/prescription/forms/__init__.py b/medical_prescription/prescription/forms/__init__.py
index 36ea0731..a2515b60 100644
--- a/medical_prescription/prescription/forms/__init__.py
+++ b/medical_prescription/prescription/forms/__init__.py
@@ -2,3 +2,4 @@
from .examprescriptionform import ExamPrescriptionForm
from .medicineprescriptionform import MedicinePrescriptionForm
from .recommendationprescriptionform import RecommendationPrescriptionForm
+from .patternform import PatternForm
diff --git a/medical_prescription/prescription/forms/patternform.py b/medical_prescription/prescription/forms/patternform.py
new file mode 100644
index 00000000..bf1a46d8
--- /dev/null
+++ b/medical_prescription/prescription/forms/patternform.py
@@ -0,0 +1,33 @@
+# Django
+from django import forms
+
+# Local Django
+from django.utils.translation import ugettext_lazy as _
+from prescription import constants
+
+
+class PatternForm(forms.Form):
+ name = forms.CharField(max_length=constants.MAX_LENGTH_NAME,
+ widget=forms.TextInput(attrs={'class': 'form-control',
+ 'type': 'text',
+ 'placeholder': _('Nome de Modelo')}))
+
+ clinic = forms.CharField(max_length=constants.MAX_LENGTH_CLINIC,
+ widget=forms.TextInput(attrs={'class': 'form-control',
+ 'type': 'text',
+ 'placeholder': _('Clinica')}))
+
+ header = forms.CharField(max_length=constants.MAX_LENGTH_HEADER,
+ widget=forms.TextInput(attrs={'class': 'form-control',
+ 'type': 'text',
+ 'placeholder': _('Header')}))
+
+ footer = forms.CharField(max_length=constants.MAX_LENGTH_FOOTER,
+ widget=forms.TextInput(attrs={'class': 'form-control',
+ 'type': 'text',
+ 'placeholder': _('Footer')}))
+
+ logo = forms.FileField(required=False)
+
+ font = forms.ChoiceField(choices=constants.FONT_CHOICE)
+ font_size = forms.ChoiceField(choices=constants.FONT_SIZE_CHOICE)
diff --git a/medical_prescription/prescription/models/__init__.py b/medical_prescription/prescription/models/__init__.py
index 091c91b0..e4304258 100644
--- a/medical_prescription/prescription/models/__init__.py
+++ b/medical_prescription/prescription/models/__init__.py
@@ -7,3 +7,4 @@
from .prescriptiondefaultexam import PrescriptionDefaultExam
from .prescriptioncustomexam import PrescriptionCustomExam
from .recommendation import Recommendation
+from .pattern import Pattern
diff --git a/medical_prescription/prescription/models/pattern.py b/medical_prescription/prescription/models/pattern.py
new file mode 100644
index 00000000..3980aaed
--- /dev/null
+++ b/medical_prescription/prescription/models/pattern.py
@@ -0,0 +1,28 @@
+# Standard
+import os
+
+# Django
+from django.db import models
+
+# Django Local
+from user.models import User
+from chat.models.pathfile import UploadToPathAndRename
+from prescription import constants
+
+
+class Pattern(models.Model):
+ """
+ Prescription PDF base model.
+ """
+ name = models.CharField(max_length=constants.MAX_LENGTH_NAME)
+ user_creator = models.ForeignKey(User, related_name="user_creator")
+
+ font = models.CharField(choices=constants.FONT_CHOICE, max_length=100, default=constants.TIMES_ROMAN)
+ font_size = models.CharField(choices=constants.FONT_SIZE_CHOICE, max_length=100, default=constants.TWELVE)
+
+ clinic = models.CharField(max_length=constants.MAX_LENGTH_CLINIC)
+ header = models.CharField(max_length=constants.MAX_LENGTH_HEADER)
+ footer = models.CharField(max_length=constants.MAX_LENGTH_FOOTER)
+
+ logo = models.FileField(upload_to=UploadToPathAndRename(os.path.join('logos', 'files')), blank=True, null=True)
+ date = models.DateField(auto_now=True)
diff --git a/medical_prescription/prescription/templates/create_prescription_model.html b/medical_prescription/prescription/templates/create_prescription_model.html
new file mode 100644
index 00000000..dde91061
--- /dev/null
+++ b/medical_prescription/prescription/templates/create_prescription_model.html
@@ -0,0 +1,88 @@
+{% extends "dashboardHealthProfessional/template.html" %}
+
+{% block content %}
+{% load staticfiles %}
+{% load static %}
+{% load i18n %}
+
+
+
+{% csrf_token %}
+
+{% endblock %}
diff --git a/medical_prescription/prescription/templates/list_prescription.html b/medical_prescription/prescription/templates/list_prescription.html
index 7d6d8def..ec256ff1 100644
--- a/medical_prescription/prescription/templates/list_prescription.html
+++ b/medical_prescription/prescription/templates/list_prescription.html
@@ -21,6 +21,7 @@
Medicamentos |
Recomendações |
Exames |
+ Imprimir |
@@ -87,6 +88,8 @@
Visualizar
+ |
+
{% endfor %}
diff --git a/medical_prescription/prescription/test/test_form_createpattern.py b/medical_prescription/prescription/test/test_form_createpattern.py
new file mode 100644
index 00000000..0ad768f2
--- /dev/null
+++ b/medical_prescription/prescription/test/test_form_createpattern.py
@@ -0,0 +1,34 @@
+from django.test import TestCase
+
+from prescription.models import Pattern
+from prescription.forms import PatternForm
+from prescription.views import CreatePatternView
+from user.models import User
+
+
+class TestFormCreatePattern(TestCase):
+ def setUp(self):
+ self.user = User()
+ self.user.email = 'email@email.com'
+ self.user.save()
+
+ self.name = "Pattern de teste"
+ self.user_creator = self.user
+ self.clinic = "clinica de teste"
+ self.header = "header de teste"
+ self.font = 'Helvetica'
+ self.font_size = '12'
+ self.footer = "footer de teste"
+
+ def test_form_is_valid(self):
+ form_data = {
+ 'name': self.name,
+ 'clinic': self.clinic,
+ 'font': 'Helvetica',
+ 'font_size': '12',
+ 'header': self.header,
+ 'footer': self.footer
+ }
+
+ form = PatternForm(data=form_data)
+ self.assertTrue(form.is_valid())
\ No newline at end of file
diff --git a/medical_prescription/prescription/test/test_view_createpattern.py b/medical_prescription/prescription/test/test_view_createpattern.py
new file mode 100644
index 00000000..eef464fe
--- /dev/null
+++ b/medical_prescription/prescription/test/test_view_createpattern.py
@@ -0,0 +1,51 @@
+from django.test import TestCase
+from django.test.client import RequestFactory, Client
+
+from prescription.models import Pattern
+from prescription.views import CreatePatternView
+from user.models import HealthProfessional
+
+
+class TestCreatePattern(TestCase):
+ def setUp(self):
+ self.factory = RequestFactory()
+
+ self.my_class = Pattern
+ self.my_view = CreatePatternView()
+
+ self.user = HealthProfessional()
+ self.user.email = 'email@email.com'
+ self.user.save()
+
+ self.name = "Pattern de teste"
+ self.user_creator = self.user
+ self.clinic = "clinica de teste"
+ self.header = "header de teste"
+ self.font = 'Helvetica'
+ self.font_size = '12'
+ self.footer = "footer de teste"
+
+ def test_pattern_redirect_valid(self):
+ data = {
+ 'name': self.name,
+ 'clinic': self.clinic,
+ 'font': 'Helvetica',
+ 'font_size': '12',
+ 'header': self.header,
+ 'footer': self.footer
+ }
+
+ request = self.factory.post('/', data)
+ request.user = self.user
+
+ response = CreatePatternView.as_view()(request)
+
+ self.assertEqual(response.status_code, 302)
+
+ def test_pattern_get(self):
+ request = self.factory.get('/prescription/create_prescription_model/')
+ request.user = self.user
+
+ # Get the response
+ response = self.my_view.get(request)
+ self.assertEqual(response.status_code, 200)
\ No newline at end of file
diff --git a/medical_prescription/prescription/test/test_view_printprescription.py b/medical_prescription/prescription/test/test_view_printprescription.py
new file mode 100644
index 00000000..7d21e4a3
--- /dev/null
+++ b/medical_prescription/prescription/test/test_view_printprescription.py
@@ -0,0 +1,225 @@
+from django.test import TestCase
+from django.test.client import RequestFactory, Client
+
+from prescription.models import (
+ Prescription,
+ PrescriptionHasManipulatedMedicine,
+ PrescriptionRecommendation,
+ PrescriptionHasMedicine,
+ PrescriptionDefaultExam,
+ PrescriptionCustomExam,
+ Recommendation
+ )
+from disease.models import Disease
+from exam.models import DefaultExam, CustomExam
+from medicine.models import Medicine, ManipulatedMedicine
+from user.models import Patient, HealthProfessional
+from prescription.views import printprescription
+
+
+class TestPrintPrescription(TestCase):
+ def setUp(self):
+ self.factory = RequestFactory()
+ self.client = Client()
+ self.view = printprescription.generate_pdf
+
+ self.patient = Patient()
+ self.patient.pk = 1
+ self.patient.name = "Paciente de teste"
+ self.patient.date_of_birth = "1991-10-21"
+ self.patient.phone = "06199999999"
+ self.patient.email = "paciente@emp.com"
+ self.patient.sex = "M"
+ self.patient.id_document = "1000331"
+ self.patient.CEP = "72850735"
+ self.patient.UF = "DF"
+ self.patient.city = "Brasília"
+ self.patient.neighborhood = "Asa sul"
+ self.patient.complement = "Bloco 2 QD 701"
+ self.patient.save()
+
+ self.health_professional = HealthProfessional()
+ self.health_professional.pk = 1
+ self.health_professional.crm = '12345'
+ self.health_professional.crm_state = 'US'
+ self.health_professional.save()
+
+ self.health_professional = HealthProfessional.objects.create_user(email='doctor@doctor.com',
+ password='senha12')
+
+ self.disease = Disease()
+ self.disease.pk = 1
+ self.disease.id_cid_10 = "A01"
+ self.disease.description = "A random disease"
+ self.disease.save()
+
+ self.prescription = Prescription()
+ self.prescription.pk = 1
+ self.prescription.health_professional = self.health_professional
+ self.prescription.cid = self.disease
+ self.prescription.save()
+
+ self.prescription_2 = Prescription()
+ self.prescription_2.pk = 2
+ self.prescription_2.health_professional = self.health_professional
+ self.prescription_2.cid = self.disease
+ self.prescription_2.save()
+
+ self.prescription_3 = Prescription()
+ self.prescription_3.pk = 3
+ self.prescription_3.health_professional = self.health_professional
+ self.prescription_3.cid = self.disease
+ self.prescription_3.save()
+
+ self.prescription_4 = Prescription()
+ self.prescription_4.pk = 4
+ self.prescription_4.health_professional = self.health_professional
+ self.prescription_4.cid = self.disease
+ self.prescription_4.save()
+
+ self.prescription_5 = Prescription()
+ self.prescription_5.pk = 5
+ self.prescription_5.health_professional = self.health_professional
+ self.prescription_5.cid = self.disease
+ self.prescription_5.save()
+
+ self.manipulated_medicine = ManipulatedMedicine()
+ self.manipulated_medicine.pk = 1
+ self.manipulated_medicine.recipe_name = "teste"
+ self.manipulated_medicine.physical_form = "asdadsafdf"
+ self.manipulated_medicine.quantity = 12
+ self.manipulated_medicine.measurement = "kg"
+ self.manipulated_medicine.composition = "aosdjoaisjdoiajsdoij"
+ self.manipulated_medicine.health_professional = self.health_professional
+ self.manipulated_medicine.save()
+
+ self.manipulated_medicine_2 = ManipulatedMedicine()
+ self.manipulated_medicine_2.pk = 2
+ self.manipulated_medicine_2.recipe_name = "teste"
+ self.manipulated_medicine_2.physical_form = "asdadsafdf"
+ self.manipulated_medicine_2.quantity = 12
+ self.manipulated_medicine_2.measurement = "kg"
+ self.manipulated_medicine_2.composition = "aosdjoaisjdoiajsdoij"
+ self.manipulated_medicine_2.health_professional = self.health_professional
+ self.manipulated_medicine_2.save()
+
+ self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
+ self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
+ self.hasmanipulated_medicine.posology = "asd"
+ self.hasmanipulated_medicine.quantity = 1
+ self.hasmanipulated_medicine.pk = 2
+ self.hasmanipulated_medicine.via = 'Via Intravenosa'
+ self.hasmanipulated_medicine.prescription_medicine = self.prescription
+ self.hasmanipulated_medicine.save()
+
+ self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
+ self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine_2
+ self.hasmanipulated_medicine.posology = "asd"
+ self.hasmanipulated_medicine.quantity = 1
+ self.hasmanipulated_medicine.pk = 12
+ self.hasmanipulated_medicine.via = 'Via Intravenosa'
+ self.hasmanipulated_medicine.prescription_medicine = self.prescription
+ self.hasmanipulated_medicine.save()
+
+ self.hasmanipulated_medicine = PrescriptionHasManipulatedMedicine()
+ self.hasmanipulated_medicine.manipulated_medicine = self.manipulated_medicine
+ self.hasmanipulated_medicine.posology = "asd"
+ self.hasmanipulated_medicine.quantity = 1
+ self.hasmanipulated_medicine.pk = 4
+ self.hasmanipulated_medicine.via = 'Via Intravenosa'
+ self.hasmanipulated_medicine.prescription_medicine = self.prescription_2
+ self.hasmanipulated_medicine.save()
+
+ self.recommendation = Recommendation()
+ self.recommendation.recommendation = "recomendacao de teste"
+ self.recommendation.save()
+
+ self.prescription_has_recommendation = PrescriptionRecommendation()
+ self.prescription_has_recommendation.prescription = self.prescription
+ self.prescription_has_recommendation.recommendation = self.recommendation
+ self.prescription_has_recommendation.save()
+
+ self.prescription_has_recommendation = PrescriptionRecommendation()
+ self.prescription_has_recommendation.prescription = self.prescription_3
+ self.prescription_has_recommendation.recommendation = self.recommendation
+ self.prescription_has_recommendation.save()
+
+ self.medicine = Medicine()
+ self.medicine.name = "asdoajsdoiasj"
+ self.medicine.active_ingredient = "dsofaksdofk"
+ self.medicine.laboratory = "dofijasoifjjf"
+ self.medicine.description = "oiajdoaisjddj"
+ self.medicine.save()
+
+ self.medicine_2 = Medicine()
+ self.medicine_2.name = "asdoajsdoiasj"
+ self.medicine_2.active_ingredient = "dsofaksdofk"
+ self.medicine_2.laboratory = "dofijasoifjjf"
+ self.medicine_2.description = "oiajdoaisjddj"
+ self.medicine_2.save()
+
+ self.prescription_has_medicine = PrescriptionHasMedicine()
+ self.prescription_has_medicine.medicine = self.medicine
+ self.prescription_has_medicine.posology = "asd"
+ self.prescription_has_medicine.quantity = 1
+ self.prescription_has_medicine.pk = 2
+ self.prescription_has_medicine.via = 'Via Intravenosa'
+ self.prescription_has_medicine.prescription_medicine = self.prescription
+ self.prescription_has_medicine.save()
+
+ self.prescription_has_medicine = PrescriptionHasMedicine()
+ self.prescription_has_medicine.medicine = self.medicine_2
+ self.prescription_has_medicine.posology = "asd"
+ self.prescription_has_medicine.quantity = 1
+ self.prescription_has_medicine.pk = 21
+ self.prescription_has_medicine.via = 'Via Intravenosa'
+ self.prescription_has_medicine.prescription_medicine = self.prescription
+ self.prescription_has_medicine.save()
+
+ self.default_exam = DefaultExam()
+ self.default_exam.id_tuss = 'oiafj'
+ self.default_exam.save()
+
+ self.custom_exam = CustomExam()
+ self.custom_exam.health_professional_FK = self.health_professional
+ self.custom_exam.save()
+
+ self.prescription_default_exam = PrescriptionDefaultExam()
+ self.prescription_default_exam.exam = self.default_exam
+ self.prescription_default_exam.prescription = self.prescription
+ self.prescription_default_exam.save()
+
+ self.prescription_default_exam = PrescriptionDefaultExam()
+ self.prescription_default_exam.exam = self.default_exam
+ self.prescription_default_exam.prescription = self.prescription_4
+ self.prescription_default_exam.save()
+
+ self.prescription_custom_exam = PrescriptionCustomExam()
+ self.prescription_custom_exam.exam = self.custom_exam
+ self.prescription_custom_exam.prescription = self.prescription
+ self.prescription_custom_exam.save()
+
+ def test_print_prescription_get(self):
+ request = self.factory.get('/prescription/print_prescription/1')
+ response = self.view(request, pk=1)
+ self.assertEqual(response.status_code, 200)
+
+ def test_print_prescription_get_invalid_medicine(self):
+ request = self.factory.get('/prescription/print_prescription/2')
+ response = self.view(request, pk=2)
+ self.assertEqual(response.status_code, 200)
+
+ def test_print_prescription_get_invalid_recommendation(self):
+ request = self.factory.get('/prescription/print_prescription/3')
+ response = self.view(request, pk=3)
+ self.assertEqual(response.status_code, 200)
+
+ def test_print_prescription_get_invalid_exam(self):
+ request = self.factory.get('/prescription/print_prescription/4')
+ response = self.view(request, pk=4)
+ self.assertEqual(response.status_code, 200)
+
+ def test_print_prescription_get_invalid(self):
+ request = self.factory.get('/prescription/print_prescription/5')
+ response = self.view(request, pk=5)
+ self.assertEqual(response.status_code, 200)
diff --git a/medical_prescription/prescription/urls.py b/medical_prescription/prescription/urls.py
index b450d173..bc702b03 100644
--- a/medical_prescription/prescription/urls.py
+++ b/medical_prescription/prescription/urls.py
@@ -8,11 +8,12 @@
OpenPrescriptionView,
AutoCompleteMedicine,
CreatePrescriptionView,
- ListPrescription,
- FavoritePrescription,
- ListFavoritePrescription,
ShowDetailPrescriptionView,
- ListPrescription)
+ ListFavoritePrescription,
+ FavoritePrescription,
+ ListPrescription,
+ printprescription,
+ CreatePatternView)
urlpatterns = (
url(r'^$', OpenPrescriptionView.as_view(), name='create_prescription'),
@@ -23,6 +24,8 @@
name='autocomplete_medicine'),
url(r'^create_modal/$', CreatePrescriptionView.as_view(), name='create_modal'),
url(r'^list_prescription/$', ListPrescription.as_view(), name='list_prescription'),
+ url(r'^print_prescription/(?P[0-9]+)/$', printprescription.generate_pdf, name='print_prescription'),
+ url(r'^create_prescription_model/$', CreatePatternView.as_view(), name='create_prescription_model'),
url(r'^favorite_prescription/(?P[0-9]+)/$', FavoritePrescription.as_view(), name='favorite_prescription'),
url(r'^list_favorite_prescription/$', ListFavoritePrescription.as_view(), name='list_favorite_prescription'),
url(r'^show_prescription/(?P[\w-]+)$', ShowDetailPrescriptionView.as_view(),
diff --git a/medical_prescription/prescription/views/__init__.py b/medical_prescription/prescription/views/__init__.py
index 76b3b547..33e422e8 100644
--- a/medical_prescription/prescription/views/__init__.py
+++ b/medical_prescription/prescription/views/__init__.py
@@ -5,6 +5,8 @@
from .autocompletemedicine import AutoCompleteMedicine
from .createprescription import CreatePrescriptionView
from .listprescription import ListPrescription
+from .header_footer import HeaderFooter
+from .createpatternview import CreatePatternView
from .favorite_prescription import FavoritePrescription
from .listfavoriteprescription import ListFavoritePrescription
from .showprescription import ShowDetailPrescriptionView
diff --git a/medical_prescription/prescription/views/createpatternview.py b/medical_prescription/prescription/views/createpatternview.py
new file mode 100644
index 00000000..c88804cd
--- /dev/null
+++ b/medical_prescription/prescription/views/createpatternview.py
@@ -0,0 +1,62 @@
+# Django
+from django.shortcuts import render, redirect
+from django.views.generic import FormView
+from datetime import date
+from django.contrib.auth.decorators import login_required
+from django.utils.decorators import method_decorator
+
+# Local Django
+from prescription.forms import PatternForm
+from prescription.models import Pattern
+from user.decorators import is_health_professional
+
+
+@method_decorator(login_required, name='dispatch')
+@method_decorator(is_health_professional, name='dispatch')
+class CreatePatternView(FormView):
+ """
+ Create a prescription Model.
+ """
+
+ form_class = PatternForm
+ template_name = 'create_prescription_model.html'
+
+ @method_decorator(login_required)
+ @method_decorator(is_health_professional)
+ def get(self, request, *args, **kwargs):
+ form = self.form_class(initial=self.initial)
+ return render(request, self.template_name, {'form': form})
+
+ @method_decorator(login_required)
+ @method_decorator(is_health_professional)
+ def post(self, request, *args, **kwargs):
+ form = self.form_class(request.POST, request.FILES)
+
+ # Validanting form.
+ if form.is_valid():
+ user_creator = request.user
+
+ name = form.cleaned_data.get('name')
+ header = form.cleaned_data.get('header')
+ footer = form.cleaned_data.get('footer')
+ clinic = form.cleaned_data.get('clinic')
+
+ font = form.cleaned_data.get('font')
+ font_size = form.cleaned_data.get('font_size')
+
+ # Create a Prescription type
+ pattern_instance = Pattern()
+ pattern_instance = Pattern(logo=request.FILES.get('logo', None))
+ pattern_instance.user_creator = user_creator
+ pattern_instance.name = name
+ pattern_instance.header = header
+ pattern_instance.footer = footer
+ pattern_instance.clinic = clinic
+ pattern_instance.font = font
+ pattern_instance.font_size = font_size
+ pattern_instance.date = date.today()
+ pattern_instance.save()
+
+ return redirect('/dashboard_health_professional/health_professional')
+
+ return render(request, self.template_name, {'form': form})
diff --git a/medical_prescription/prescription/views/header_footer.py b/medical_prescription/prescription/views/header_footer.py
new file mode 100644
index 00000000..2872cd54
--- /dev/null
+++ b/medical_prescription/prescription/views/header_footer.py
@@ -0,0 +1,52 @@
+import os
+
+# Third-Party
+from reportlab.lib.units import inch
+from reportlab.pdfgen import canvas
+from reportlab.lib.pagesizes import LETTER
+from reportlab.lib.utils import ImageReader
+
+
+class HeaderFooter(canvas.Canvas):
+ def __init__(self, *args, **kwargs):
+ canvas.Canvas.__init__(self, *args, **kwargs)
+ self.pages = []
+
+ def showPage(self):
+ self.pages.append(dict(self.__dict__))
+ self._startPage()
+
+ def save(self):
+ page_count = len(self.pages)
+ for page in self.pages:
+ self.__dict__.update(page)
+ self.draw_canvas(page_count)
+ canvas.Canvas.showPage(self)
+ canvas.Canvas.save(self)
+
+ def draw_canvas(self, page_count):
+ page = "Page %s of %s" % (self._pageNumber, page_count)
+ # logo = ImageReader("medical_prescription/static/img/user.png")
+
+ x = 128
+ self.saveState()
+ self.setStrokeColorRGB(0, 0, 0)
+ self.setLineWidth(0.5)
+ self.line(66, 78, LETTER[0] - 66, 78)
+ self.setFont('Times-Roman', 10)
+ self.drawString(LETTER[0]-x, 65, page)
+ self.setLineWidth(.3)
+
+ # self.drawImage(logo, 30, 730, 0.75*inch, 0.75*inch, mask='auto')
+
+ self.drawString(30, 715, 'CLINICA ALGUM')
+ self.drawString(30, 705, 'NOME LOGO')
+ self.drawString(500, 750, "12/12/2010")
+
+ self.drawString(275, 725, 'PACIENTE:')
+ self.drawString(500, 725, "ALGUM NOME")
+ self.line(378, 723, 580, 723)
+
+ self.line(30, 703, 580, 700)
+
+ self.restoreState()
diff --git a/medical_prescription/prescription/views/printprescription.py b/medical_prescription/prescription/views/printprescription.py
new file mode 100644
index 00000000..40de66d6
--- /dev/null
+++ b/medical_prescription/prescription/views/printprescription.py
@@ -0,0 +1,101 @@
+# Standard
+from io import BytesIO
+
+# Django
+from django.http import HttpResponse
+from django.contrib.auth.decorators import login_required
+from django.utils.decorators import method_decorator
+
+# Local Django imports
+from user.decorators import is_health_professional
+from prescription.models import Prescription
+from prescription.views import HeaderFooter
+
+# Third-Party
+from reportlab.lib.pagesizes import letter
+from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
+from reportlab.lib.enums import TA_CENTER
+from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
+
+
+# @method_decorator(login_required)
+# @method_decorator(is_health_professional)
+def generate_pdf(request, pk):
+ response = HttpResponse(content_type='application/pdf')
+ response['Content-Disposition'] = 'attachment; filename="My Users.pdf"'
+
+ prescription = Prescription.objects.get(pk=pk)
+
+ buffer = BytesIO()
+
+ doc = SimpleDocTemplate(buffer,
+ rightMargin=100,
+ leftMargin=100,
+ topMargin=100,
+ bottomMargin=100,
+ pagesize=letter)
+
+ elements = []
+
+ styles = getSampleStyleSheet()
+ styles.add(ParagraphStyle(name='centered', alignment=TA_CENTER))
+
+ # Draw things on the PDF. Here's where the PDF generation happens.
+
+ if len(prescription.medicines.all()) != 0 or prescription.manipulated_medicines.all() != 0:
+ elements.append(Paragraph('Medicamentos', styles['Heading1']))
+ for medicine in prescription.medicines.all():
+ elements.append(Paragraph(medicine.name, styles['Normal']))
+
+ for prescription_medicine in prescription.prescriptionhasmedicine_set.all():
+ if prescription_medicine.medicine == medicine:
+ elements.append(Paragraph(prescription_medicine.via, styles['Normal']))
+ elements.append(Paragraph(prescription_medicine.posology, styles['Normal']))
+ elements.append(Paragraph(prescription_medicine.get_quantity_display(), styles['Normal']))
+ elements.append(Spacer(1, 12))
+
+ for custom_medicine in prescription.manipulated_medicines.all():
+ elements.append(Paragraph(custom_medicine.recipe_name, styles['Normal']))
+
+ for custom_prescription_medicine in prescription.prescriptionhasmanipulatedmedicine_set.all():
+ if custom_prescription_medicine.manipulated_medicine == custom_medicine:
+ elements.append(Paragraph(custom_prescription_medicine.via, styles['Normal']))
+ elements.append(Paragraph(custom_prescription_medicine.posology, styles['Normal']))
+ elements.append(Paragraph(custom_prescription_medicine.get_quantity_display(), styles['Normal']))
+ elements.append(Spacer(1, 12))
+ else:
+ # Nothing to do.
+ pass
+
+ elements.append(Spacer(1, 12))
+ if len(prescription.recommendation_prescription.all()) != 0:
+ elements.append(Paragraph('Recomendacoes', styles['Heading1']))
+ for recommendation in prescription.recommendation_prescription.all():
+ elements.append(Paragraph(recommendation.recommendation, styles['Normal']))
+ elements.append(Spacer(1, 12))
+ else:
+ # Nothing to do.
+ pass
+
+ elements.append(Spacer(1, 12))
+ if len(prescription.default_exams.all()) != 0 or len(prescription.custom_exams.all()) != 0:
+ elements.append(Paragraph('Exames', styles['Heading1']))
+ for default_exams in prescription.default_exams.all():
+ elements.append(Paragraph(default_exams.description, styles['Normal']))
+ elements.append(Spacer(1, 12))
+
+ for custom_exams in prescription.custom_exams.all():
+ elements.append(Paragraph(custom_exams.description, styles['Normal']))
+ elements.append(Spacer(1, 12))
+
+ else:
+ # NOTHING TO DO
+ pass
+
+ doc.build(elements, canvasmaker=HeaderFooter)
+
+ pdf = buffer.getvalue()
+ buffer.close()
+
+ response.write(pdf)
+ return response
diff --git a/medical_prescription/templates/dashboardHealthProfessional/side_bar.html b/medical_prescription/templates/dashboardHealthProfessional/side_bar.html
index 4c790a2f..06cc8348 100644
--- a/medical_prescription/templates/dashboardHealthProfessional/side_bar.html
+++ b/medical_prescription/templates/dashboardHealthProfessional/side_bar.html
@@ -45,6 +45,7 @@