Skip to content

Commit

Permalink
Edição de paciente funcional
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigmars committed May 22, 2024
1 parent 7dec42f commit ee935de
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 16 deletions.
12 changes: 10 additions & 2 deletions auto-complete.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!DOCTYPE html>

<html lang="pt-br">
<meta name="description" content="">
<meta name="keywords" content="">

<head>
<meta charset="UTF-8">
Expand All @@ -8,7 +11,10 @@
</head>

<body>

<form action="" method="get">
<input type="hidden" name="csrfmiddlewaretoken"
value="yrqsWxNtbREiKWaVjKjZ6KFlcdE3ct80bkGMQgeRmd78Iw3c6ognSkteA5ULq0gc">
</form>
</body>

</html>
Expand All @@ -17,7 +23,9 @@

; (atlas => {

console.info(`atlas ${atlas}`)
const csrToken = atlas.querySelector("[name=csrfmiddlewaretoken]")

console.info(`csrToken ${csrToken.value}`)

})(document)

Expand Down
26 changes: 25 additions & 1 deletion pacientes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from cProfile import label
from queue import Empty
from django import forms

import pacientes
from .utils import AGENDAMENTO_FIXO_CHOICES, GENERO_CHOICES
from .models import Paciente
from common.util import CommonsUtil
Expand All @@ -16,6 +18,16 @@

class PacienteForm(forms.ModelForm, CommonsUtil):

# hidden_id = forms.CharField(
# required=False,
# widget=forms.HiddenInput(
# attrs={
# "name": "hdnPacienteId",
# "id": "hdnPacienteId",
# }
# ),
# )

nome = forms.CharField(
max_length=60,
required=False,
Expand Down Expand Up @@ -145,6 +157,8 @@ def clean(self):

errors = {}

paciente_id = self.instance.pk

nome = self.cleaned_data.get("nome")

data_de_nascimento = self.cleaned_data.get("data_de_nascimento")
Expand Down Expand Up @@ -209,7 +223,17 @@ def clean(self):
)
else:

if Paciente.objects.filter(cartao_sus=cartao_sus).count() >= 1:
if paciente_id:

if (
Paciente.objects.filter(cartao_sus=cartao_sus)
.exclude(id=paciente_id)
.exists()
):
errors["cartao_sus"] = (
"Já existe um mesmo Cartão SUS cadastrado"
)
elif Paciente.objects.filter(cartao_sus=cartao_sus).exists():
errors["cartao_sus"] = "Já existe um mesmo Cartão SUS cadastrado"

if not agendamento_fixo:
Expand Down
46 changes: 46 additions & 0 deletions pacientes/templates/editar_paciente.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "base.html" %}
{% load static poll_extras %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/patient-form.css' %}">
{% endblock css %}
{% block title %}
Editar Paciente
{% endblock title %}
{% block content %}

<form action="{% url 'editar_paciente' id %}" method="post" class="form_row" name="frmPaciente" id="frmPaciente">
{% csrf_token %}
<input type="hidden" id="hdnPacienteId" name="hdnPacienteId" value="55555" />
<div class="row">
<div class="col-5">
<h2>Cadastro de Paciente</h2>
</div>
</div>
{% for field in form %}
{% if field.name|is_fieldset %}
<div class="row">
<fieldset>
<legend class="{{ field.errors|yesno:" error," }}">{{ field|set_label }}</legend>
{{ field }}
</fieldset>
</div>
{% else %}
<div class="row">
<div class="col-5 {{ field.errors|yesno:" error," }}">{{ field.label_tag }}</div>
</div>
<div class="row">
<div class="{{ field|set_column_input }}">{{ field }}</div>
</div>
{% endif %}
<div class="row">
<div class="col-5 error">{{ field.errors }}</div>
</div>
{% endfor %}
<div class="row">
<div class="col-5">
<input type="submit" value="Confirmar">
</div>
</div>
</form>
<script src="{% static 'js/patient-form.js' %}"></script>
{% endblock content %}
4 changes: 2 additions & 2 deletions pacientes/templates/lista_pacientes.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<td>{{ paciente.nome }}</td>
<td>{{ paciente.cartao_sus }}</td>
<td>
<input type="button" value="Editar">
<a href="{% url 'editar_paciente' paciente.id %}">Editar</a>
</td>
<td>
<input type="button" value="Excluir">
<a href="{% url 'excluir_paciente' paciente.id %}">Excluir</a>
</td>
</tr>
{% endfor %}
Expand Down
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="criar_paciente"),
path("edita/<int:id>", views.atualizar, name="edita_paciente"),
path("exclui/<int:id>", views.excluir, name="exclui_paciente"),
path("edita/<int:id>", views.atualizar, name="editar_paciente"),
path("exclui/<int:id>", views.excluir, name="excluir_paciente"),
]
21 changes: 15 additions & 6 deletions pacientes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,33 @@ def cadastrar(request):
return render(request, "criar_paciente.html", context)


def atualizar(request, pk: int):
def atualizar(request, id: int):

context = {}

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

print(">>>>>>>id paciente", paciente.pk)

if request.method == "POST":

context["form"] = PacienteForm(request.POST, instance=paciente)

print("is_valid>>>", context["form"].is_valid())

if context["form"].is_valid():

# print(context["form"].cleaned_data)
context["form"].save()

return redirect("paciente-detail", paciente.pk)
else:
context["form"] = PacienteForm(instance=paciente)
return redirect("editar_paciente", paciente.pk)

context["erros"] = context["form"].errors.as_data()

print(context["erros"])

context["id"] = paciente.pk

context["form"] = PacienteForm(instance=paciente)

return render(request, "editar_paciente.html", context)

Expand Down
3 changes: 0 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<li>
<a href="{% url 'lista_pacientes' %}">Pacientes</a>
</li>
<li>
<a href="{% url 'lista_usuarios' %}">Usuários</a>
</li>
</ul>
</form>

Expand Down

0 comments on commit ee935de

Please sign in to comment.