Skip to content

Commit

Permalink
Estrutura form definida para app pacientes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigmars committed Apr 17, 2024
1 parent 2f6547d commit 4ffedc8
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 95 deletions.
4 changes: 0 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@ <h1>Cadastre-se</h1>
<label for="email">SUS</label>
<input id="email" type="email" name="email" placeholder="Digite seu SUS" required>
</div>

<div class="input-box">
<label for="number">Telefone</label>
<input id="number" type="tel" name="number" placeholder="(xx) xxxx-xxxx" required>
</div>

<div class="input-box">
<label for="password">Endereço</label>
<input id="password" type="password" name="password" placeholder="Digite seu Endereço" required>
</div>


<div class="input-box">
<label for="confirmPassword">Data do transporte</label>
<input id="confirmPassword" type="password" name="confirmPassword"
Expand Down
46 changes: 46 additions & 0 deletions pacientes/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# <strong>Estados</strong>
# <strong>Capitais</strong>
# <strong>Siglas</strong>


estados = [
{"AC": {1: {"Acre": [{1: ("Rio Branco", 0)}, {}]}}},
{"AL": ["Alagoas", "Maceió"]},
{"AP": ["Amapá", "Macapá"]},
{"AM": ["Amazonas", "Manaus"]},
{"BA": ["Bahia", "Salvador"]},
{"CE": ["Ceará", "Fortaleza"]},
{"DF": ["Distrito Federal", "Brasília", (61,)]},
{"ES": ["Espírito Santo", "Vitória"]},
{"GO": ["Goiás", "Goiânia", (62, 64)]},
{"MA": ["Maranhão", "São Luís"]},
{"MT": ["Mato Grosso", "Cuiabá", (65, 66)]},
{"MS": ["Mato Grosso do Sul", "Campo Grande", (67,)]},
{"MG": ["Minas Gerais", "Belo Horizonte"]},
{"PA": ["Pará", "Belém"]},
{"PB": ["Paraíba", "João Pessoa"]},
{"PR": ["Paraná", "Curitiba"]},
{"PE": ["Pernambuco", "Recife"]},
{"PI": ["Piauí", "Teresina"]},
{"RJ": ["Rio de Janeiro", "Rio de Janeiro"]},
{"RN": ["Rio Grande do Norte", "Natal"]},
{"RS": ["Rio Grande do Sul", "Porto Alegre"]},
{"RO": ["Rondônia", "Porto Velho"]},
{"RR": ["Roraima", "Boa Vista"]},
{"SC": ["Santa Catarina", "Florianópolis"]},
{"SP": ["São Paulo", "São Paulo"]},
{"SE": ["Sergipe", "Aracaju"]},
{"TO": ["Tocantins", "Palmas"]},
]


def listar_estados() -> list:
return []


def listar_municipios() -> list:
return []


def listar_ddd(municipio: str) -> list:
return []
104 changes: 93 additions & 11 deletions pacientes/forms.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,97 @@
from typing import Any
from django import forms
from .models import Paciente
from django.core.validators import MinValueValidator, MaxValueValidator, RegexValidator


class PacienteForm(forms.Form):
class PacienteForm(forms.ModelForm):

nome = forms.CharField(label="Nome", max_length=100)
email = forms.CharField(label="Email", max_length=100)
telefone = forms.CharField(label="Telefone", max_length=100)
dataNascimento = forms.CharField(label="Data Nascimento", max_length=100)
estadoCivil = forms.CharField(label="Estado Civil", max_length=100)
genero = forms.CharField(label="Genero", max_length=100)
bairro = forms.CharField(label="Bairro", max_length=100)
uf = forms.CharField(label="UF", max_length=100)
municipio = forms.CharField(label="Município", max_length=100)
nascionalidade = forms.CharField(label="Nascionalidade", max_length=100)
class Genero(models.IntegerChoices):
FEMININO = 1
MASCULINO = 2
OUTROS = 3

nome = (
forms.CharField(
validators=[
MinValueValidator(
3, "Limite mínimo de 3 caracteres permitido para campo Nome"
),
MaxValueValidator(
30,
message="Limite máximo de 30 caracteres permitido para campo Nome",
),
RegexValidator(
regex=r"[^a-zA-Z_-\\s]+",
message="Informe apenas texto para campo Nome",
),
],
required=True,
max_length=30,
widget=forms.TextInput(
attrs={
"placeholder": "Nome",
"class": "form-text-input",
"name": "name",
"id": "nome",
}
),
),
)

sobre_nome = (
forms.CharField(
validators=[
MinValueValidator(
3, "Limite mínimo de 3 caracteres permitido para 'Sobre nome'"
),
MaxValueValidator(
60,
message="Limite máximo de 30 caracteres permitido para campo 'Sobre nome'",
),
RegexValidator(
regex=r"[^a-zA-Z_-\\s]+",
message="Informe apenas texto para campo Sobre 'Sobre nome'",
),
],
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "Sobre nome",
"class": "form-text-input",
"name": "sobreNome",
"id": "sobreNome",
}
),
),
)

genero = forms.ChoiceField(choices=Genero, widget=forms.RadioSelect())

def clean(self):

super(PacienteForm, self).clean()

class Meta:
model = Paciente
fields = (
"nome",
"email",
"telefone",
"dataNascimento",
"genero",
"bairro",
"numero",
"complemento",
"ponto_de_refencia",
)

# nome = forms.CharField(label="Nome", max_length=100)
# email = forms.CharField(label="Email", max_length=100)
# telefone = forms.CharField(label="Telefone", max_length=100)
# dataNascimento = forms.CharField(label="Data Nascimento", max_length=100)
# genero = forms.CharField(label="Genero", max_length=100)
# bairro = forms.CharField(label="Bairro", max_length=100)
# numero = forms.CharField(label="Número", max_length=100)
# complemento = forms.CharField(label="Complemento", max_length=100)
# ponto_de_refencia = forms.CharField(label="Ponto de refencia", max_length=100)
30 changes: 29 additions & 1 deletion pacientes/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
from enum import IntEnum
from django.db import models

# Create your models here.

class Paciente(models.Model):

class Status(models.IntegerChoices):
ATIVO = 1
INATIVO = 2

nome = models.CharField(max_length=30)
sobre_nome = models.CharField(max_length=60)
data_de_nascimento = models.DateTimeField()
genero = models.IntegerField()
cartao_sus = models.CharField(max_length=15, unique=True)
telefone = models.CharField(max_length=14)
rua = models.CharField(max_length=60)
numero = models.IntegerField()
complemento = models.CharField(max_length=60)
ponto_referencia = models.CharField(max_length=50)

status = models.IntegerField(default=Status.ATIVO)

data_criacao = models.DateTimeField()
data_alteracao = models.DateTimeField()

def __str__(self):
return f"{self.nome} {self.sobre_nome}"

class Meta:
db_table = "pacientes"
75 changes: 5 additions & 70 deletions pacientes/templates/formulario_paciente.html
Original file line number Diff line number Diff line change
@@ -1,84 +1,19 @@
{% extends "base.html" %}
{% block title %}
Cadastro Paciente
Cadastro Paciente
{% endblock title %}
{% block content %}
<div class="form">

<form action="{% url 'cadastra_paciente' %}" method="POST">
<form class="form" action="{% url 'cadastra_paciente' %}" method="post">
{% csrf_token %}

<div class="form-header">
<div class="title">
<h1>Novo Paciente</h1>
</div>
</div>

<div class="input-group">
<div class="input-box">
<label for="nome">Primeiro Nome</label>
<input id="nome" type="text" name="nome" placeholder="Digite seu primeiro nome" required="">
</div>

<div class="input-box">
<label for="sobreNome">Sobrenome</label>
<input id="sobreNome" type="text" name="sobreNome" placeholder="Digite seu sobrenome" required="">
</div>
<div class="input-box">
<label for="email">SUS</label>
<input id="email" type="text" name="email" placeholder="Digite seu SUS" required="">
</div>

<div class="input-box">
<label for="telefone">Telefone</label>
<input id="telefone" type="tel" name="telefone" placeholder="(xx) xxxx-xxxx" required="">
</div>

<div class="input-box">
<label for="senha">Endereço</label>
<input id="senha" type="password" name="senha" placeholder="Digite seu Endereço" required="">
</div>


<div class="input-box">
<label for="confirmaSenha">Data do transporte</label>
<input id="confirmaSenha" type="password" name="confirmaSenha" placeholder="Data do transporte"
required="">
</div>

</div>

<div class="gender-inputs">
<div class="gender-title">
<h6>Gênero</h6>
</div>

<div class="gender-group">
<div class="gender-input">
<input id="feminimo" type="radio" name="genero">
<label for="feminimo">Feminino</label>
</div>

<div class="gender-input">
<input id="masculino" type="radio" name="genero">
<label for="masculino">Masculino</label>
</div>

<div class="gender-input">
<input id="outro" type="radio" name="genero">
<label for="outro">Outros</label>
</div>

<div class="gender-input">
<input id="semGenero" type="radio" name="genero">
<label for="semGenero">Prefiro não dizer</label>
</div>
</div>
</div>

{% if status == '1' %}<div class="message-success">{{ message }}</div>{% endif %}
{{ form.as_p }}
<div class="continue-button">
<button type="submit">Confirmar</button>
</div>
</form>
</div>
{% endblock content %}
{% endblock content %}
4 changes: 2 additions & 2 deletions pacientes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
urlpatterns = [
path("", views.listar, name="lista_pacientes"),
path("cadastro/", views.cadastrar, name="cadastra_paciente"),
path("edita/", views.atualizar, name="edita_paciente"),
path("exclui/", views.excluir, name="exclui_paciente"),
path("edita/<int:id>", views.atualizar, name="edita_paciente"),
path("exclui/<int:id>", views.excluir, name="exclui_paciente"),
]
54 changes: 47 additions & 7 deletions pacientes/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from .models import Paciente
from .forms import PacienteForm


Expand All @@ -10,7 +11,35 @@ def listar(request):

def cadastrar(request):

print(type(request))
# form = PacienteForm()

# paciente = Paciente.objects.all()

# context = {"paciente": paciente, "title": "Cadastro de Paciente", "form": form}

# return render(request, "formulario_paciente", context)

context = {}

context["form"] = PacienteForm()
context["title"] = "Cadastro de Paciente"

if request.method == "POST":

form = PacienteForm(request.POST)

if form.is_valid():
try:
# form.save()
print(form.cleaned_data)

return redirect("/lista_pacientes/")
except:
return render(request, "formulario_paciente", context)
else:
context["erros"] = form.errors

return render(request, "formulario_paciente", context)

# if request.method == "POST":

Expand All @@ -30,12 +59,23 @@ def cadastrar(request):

# form = PacienteForm()

return render(request, "formulario_paciente.html", {"form": ""})

def atualizar(request, pk: int):

def atualizar(request):
return render(request, "formulario_paciente.html")
if request.method == "POST":

paciente = Paciente.objects.get(id=pk)

def excluir(request):
return render(request, "lista_pacientes.html")
form = PacienteForm(instance=paciente)

return redirect("/lista_pacientes/")


def excluir(request, pk: int):

if request.method == "POST":

paciente = Paciente.objects.get(id=pk)
paciente.delete()

return redirect("/lista_pacientes/")

0 comments on commit 4ffedc8

Please sign in to comment.