Skip to content

Commit

Permalink
Merge pull request #178 from fga-gpp-mds/devel
Browse files Browse the repository at this point in the history
US41-PrintPrescription
  • Loading branch information
maugustoo authored Nov 19, 2017
2 parents 0ef5390 + 585b511 commit 46908ad
Show file tree
Hide file tree
Showing 20 changed files with 718 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class HealthProfessional(models.Model, User)
*.pyc
__pycache__
virtual/
.vscode/
.idea/
db.sqlite3
.DS_Store
.coverage
Expand Down
2 changes: 2 additions & 0 deletions medical_prescription/chat/models/response.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion medical_prescription/prescription/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
PrescriptionRecommendation,
NoPatientPrescription,
PatientPrescription,
Recommendation
Recommendation,
Pattern
)

admin.site.register(Prescription)
Expand All @@ -22,3 +23,4 @@
admin.site.register(PatientPrescription)
admin.site.register(NoPatientPrescription)
admin.site.register(Recommendation)
admin.site.register(Pattern)
22 changes: 22 additions & 0 deletions medical_prescription/prescription/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
1 change: 1 addition & 0 deletions medical_prescription/prescription/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .examprescriptionform import ExamPrescriptionForm
from .medicineprescriptionform import MedicinePrescriptionForm
from .recommendationprescriptionform import RecommendationPrescriptionForm
from .patternform import PatternForm
33 changes: 33 additions & 0 deletions medical_prescription/prescription/forms/patternform.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions medical_prescription/prescription/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .prescriptiondefaultexam import PrescriptionDefaultExam
from .prescriptioncustomexam import PrescriptionCustomExam
from .recommendation import Recommendation
from .pattern import Pattern
28 changes: 28 additions & 0 deletions medical_prescription/prescription/models/pattern.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{% extends "dashboardHealthProfessional/template.html" %}

{% block content %}
{% load staticfiles %}
{% load static %}
{% load i18n %}

<!-- Panel -->

{% csrf_token %}
<div class = "col-sm-4 center-block center">
<form action='' method="POST" enctype="multipart/form-data">

{% csrf_token %}

<font size="5">
<span class="label label-primary">{% trans "Nome do Modelo" %}</span>
</font>
{% for error in form.name.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.name }}

<br>

<font size="5">
<span class="label label-primary">{% trans "Clinica" %}</span>
</font>
{% for error in form.clinic.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.clinic }}

<br>

<font size="5">
<span class="label label-primary">{% trans "Header" %}</span>
</font>
{% for error in form.header.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.header }}

<br>

<font size="5">
<span class="label label-primary">{% trans "Footer" %}</span>
</font>
{% for error in form.footer.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.footer }}
<br>


<font size ="5">
<span class="label label-primary">{% trans "Fonte" %}</span>
</font>
{% for error in form.font.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.font }}
<br>

<font size="5">
<span class="label label-primary">{% trans "Tamanho da Fonte" %}</span>
</font>
{% for error in form.font_size.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.font_size }}
<br>

<font size="5">
<span class="label label-primary">{% trans "Logo" %}</span>
</font>
{% for error in form.logo.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.logo }}
<br>

<br><br>

<button type ="submit" class = "btn btn-success">{% trans "Enviar" %}</button>
</form>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<th>Medicamentos</th>
<th>Recomendações</th>
<th>Exames</th>
<th>Imprimir</th>
</thead>

<tbody>
Expand Down Expand Up @@ -87,6 +88,8 @@
<a class="js-show-prescription" data-url="{% url 'show_prescription' prescription.pk %}">Visualizar</a>
</td>

<td><a href='{% url 'print_prescription' prescription.id %}'><i class="fa fa-print"></i></a></td>

</tr>
{% endfor %}

Expand Down
34 changes: 34 additions & 0 deletions medical_prescription/prescription/test/test_form_createpattern.py
Original file line number Diff line number Diff line change
@@ -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 protected]'
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())
51 changes: 51 additions & 0 deletions medical_prescription/prescription/test/test_view_createpattern.py
Original file line number Diff line number Diff line change
@@ -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 protected]'
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)
Loading

0 comments on commit 46908ad

Please sign in to comment.