diff --git a/condicoes/views.py b/condicoes/views.py index 8d70af8..df63b29 100644 --- a/condicoes/views.py +++ b/condicoes/views.py @@ -39,7 +39,7 @@ def cadastrar(request, paciente_id: int): except: messages.error( - request, "Ocorreu um erro durante o registo, tente novamente" + request, "Ocorreu um erro durante o registro, tente novamente" ) return render(request, "criar_condicao.html", context) diff --git a/pacientes/templatetags/poll_extras_pacientes.py b/pacientes/templatetags/poll_extras_pacientes.py index a4b5efb..850e0b4 100644 --- a/pacientes/templatetags/poll_extras_pacientes.py +++ b/pacientes/templatetags/poll_extras_pacientes.py @@ -20,19 +20,6 @@ def set_label(field: BoundField) -> str: @register.filter(name="set_column_input") def set_column_input(field: BoundField) -> str: - # fields = { - # "nome": "col-5", - # "data_de_nascimento": "col-1", - # "genero": "col-5", - # "cartao_sus": "col-2", - # "agendamento_fixo": "col-5", - # "telefone": "col-2", - # "rua": "col-5", - # "numero": "col-2", - # "complemento": "col-4", - # "ponto_referencia": "col-4", - - # } fields = { "nome": "col-5", "data_de_nascimento": "col-1", @@ -44,16 +31,6 @@ def set_column_input(field: BoundField) -> str: "numero": "col-2", "complemento": "col-4", "ponto_referencia": "col-4", - "data_de_transporte": "col-2", - "horario_de_atendimento": "col-2", - "motivo_de_transporte": "col-3", - "descricao_motivo": "col-5", - "rua": "col-5", - "bairro": "col-5", - "numero": "col-5", - "cidade": "col-5", - "destino": "col-5", - "observacao": "col-5", } return fields[field.name] diff --git a/pacientes/views.py b/pacientes/views.py index 4338110..648d2cb 100644 --- a/pacientes/views.py +++ b/pacientes/views.py @@ -39,7 +39,7 @@ def cadastrar(request): except: messages.error( - request, "Ocorreu um erro durante o registo, tente novamente" + request, "Ocorreu um erro durante o registro, tente novamente" ) return render(request, "criar_paciente.html", context) diff --git a/transportes/forms.py b/transportes/forms.py index 9e7d0c1..3b8b602 100644 --- a/transportes/forms.py +++ b/transportes/forms.py @@ -1,11 +1,8 @@ -from email.policy import default from django import forms - - +from common.util import CommonsUtil from .utils import MOTIVO_CHOICES - from .models import Transporte -from common.util import CommonsUtil +from datetime import datetime, time class TransporteForm(forms.ModelForm, CommonsUtil): @@ -27,6 +24,7 @@ class TransporteForm(forms.ModelForm, CommonsUtil): horario_de_atendimento = forms.TimeField( label="Horário de Atendimento", + required=False, widget=forms.TimeInput( attrs={ "type": "time", @@ -55,17 +53,27 @@ class TransporteForm(forms.ModelForm, CommonsUtil): ), ) - rua = forms.CharField() + rua = forms.CharField( + required=False, + ) - bairro = forms.CharField() + bairro = forms.CharField( + required=False, + ) numero = forms.CharField( label="Número", + required=False, + max_length=7, ) - cidade = forms.CharField() + cidade = forms.CharField( + required=False, + ) - destino = forms.CharField() + destino = forms.CharField( + required=False, + ) observacao = forms.CharField( label="Observação", @@ -93,157 +101,110 @@ def clean(self): # paciente_id = self.instance.pk - # nome = self.cleaned_data.get("nome") - - # data_de_nascimento = self.cleaned_data.get("data_de_nascimento") - - # genero = self.cleaned_data.get("genero") - - # cartao_sus = self.cleaned_data.get("cartao_sus") - - # agendamento_fixo = self.cleaned_data.get("agendamento_fixo") - - # telefone = self.cleaned_data.get("telefone") - - # rua = self.cleaned_data.get("rua") - - # numero = self.cleaned_data.get("numero") - - # complemento = self.cleaned_data.get("complemento") - - # ponto_referencia = self.cleaned_data.get("ponto_referencia") + data_de_transporte = self.cleaned_data.get("data_de_transporte") - # if not nome: - # errors["nome"] = "Campo nome obrigatório" + horario_de_atendimento = self.cleaned_data.get("horario_de_atendimento") - # if nome: + motivo_de_transporte = self.cleaned_data.get("motivo_de_transporte") - # if len(nome) < 5 or len(nome) > 60: - # errors["nome"] = ( - # "Certifique-se de que o valor tenha entre 5 a 60 caracteres" - # ) + descricao_motivo = self.cleaned_data.get("descricao_motivo") - # elif not self.is_alpha_pattern(nome): - # errors["nome"] = ( - # "Certifique-se de que o valor tenha apenas caracteres texto" - # ) + rua = self.cleaned_data.get("rua") - # if not data_de_nascimento: - # errors["data_de_nascimento"] = "Campo data de nascimento obrigatório" + bairro = self.cleaned_data.get("bairro") - # if data_de_nascimento: + numero = self.cleaned_data.get("numero") - # ano = int(datetime.now().year - (data_de_nascimento.year)) + cidade = self.cleaned_data.get("cidade") - # if ano == -1 or ano > 100: - # errors["data_de_nascimento"] = "Informe uma data de nascimento válida" + destino = self.cleaned_data.get("destino") - # if not genero: - # errors["genero"] = "Campo gênero obrigatório" + observacao = self.cleaned_data.get("observacao") - # if not cartao_sus: - # errors["cartao_sus"] = "Campo cartão SUS obrigatório" + if not data_de_transporte: + errors["data_de_transporte"] = "Campo data de transporte obrigatório" - # if cartao_sus: + if data_de_transporte: - # if len(cartao_sus) != 15: - # errors["cartao_sus"] = ( - # "Campo cartão SUS deve possuir um tamanho de 15 dígitos" - # ) + if data_de_transporte.year != datetime.now().year: + errors["data_de_transporte"] = "Informe uma data de transporte válida" - # elif not self.is_numeric_pattern(cartao_sus): - # errors["cartao_sus"] = ( - # "Formato de campo inválido para cartão SUS, informe apenas números" - # ) - # else: + if not horario_de_atendimento: + errors["horario_de_atendimento"] = "Campo data de atendimento obrigatório" - # if paciente_id: + if horario_de_atendimento: - # if ( - # Condicao.objects.filter(cartao_sus=cartao_sus) - # .exclude(id=paciente_id) - # .exists() - # ): - # errors["cartao_sus"] = ( - # "Já existe um mesmo Cartão SUS cadastrado" - # ) - # elif Condicao.objects.filter(cartao_sus=cartao_sus).exists(): - # errors["cartao_sus"] = "Já existe um mesmo Cartão SUS cadastrado" + start_time = time(8, 0, 0) - # if not agendamento_fixo: - # errors["agendamento_fixo"] = "Selecione uma opção para agendamento fixo" + end_time = time(17, 0, 0) - # if not telefone: - # errors["telefone"] = "Campo telefone obrigatório" + if horario_de_atendimento < start_time or horario_de_atendimento > end_time: + errors["horario_de_atendimento"] = ( + f"Erro: Hora de atendimento deve respeitar janela das {start_time.hour}hrs às {end_time.hour}hrs" + ) - # if telefone: + if motivo_de_transporte == "0": + errors["motivo_de_transporte"] = "Selecione motivo para o transporte" - # telefone = self.remove_characters(telefone) + if not descricao_motivo: + errors["descricao_motivo"] = "Campo descricao motivo obrigatório" - # if len(telefone) != 13 or not self.is_phone_pattern(telefone): - # errors["telefone"] = ( - # "Certifique-se de que o número de telefone esteja correto" - # ) + if descricao_motivo: - # else: - # self.cleaned_data["telefone"] = telefone + if len(descricao_motivo) < 10 or len(descricao_motivo) > 160: + errors["descricao_motivo"] = ( + "Certifique-se de que o valor tenha entre 10 a 160 caracteres" + ) - # if not rua: - # errors["rua"] = "Campo rua obrigatório" + if not rua: + errors["rua"] = "Campo rua obrigatório" - # if rua: + if rua: - # if len(rua) < 5 or len(rua) > 60: - # errors["rua"] = ( - # "Certifique-se de que o valor tenha entre 5 a 60 caracteres" - # ) + if len(rua) < 5 or len(rua) > 60: + errors["rua"] = ( + "Certifique-se de que o valor tenha entre 5 a 60 caracteres" + ) - # elif not self.is_alpha_numeric_character_pattern(rua): - # errors["rua"] = ( - # "Certifique-se de que o valor tenha apenas caracteres texto" - # ) + elif not self.is_alpha_numeric_character_pattern(rua): + errors["rua"] = ( + "Certifique-se de que o valor tenha apenas caracteres texto" + ) - # if not numero: - # errors["numero"] = "Campo número obrigatório" + if not bairro: + errors["bairro"] = "Campo bairro obrigatório" - # if numero: + if not numero: + errors["numero"] = "Campo número obrigatório" - # if len(numero) > 7: - # errors["numero"] = ( - # "Certifique-se de que o valor tenha no máximo 7 caracteres" - # ) + if numero: - # elif not self.find_numbers(numero): - # errors["numero"] = "Certifique-se de que valor informado tenha números" + if len(numero) > 7: + errors["numero"] = "Campo número permite no máximo 7 caracteres" - # elif not self.is_alpha_numeric_character_pattern(numero): - # errors["numero"] = ( - # "Certifique-se de que valor informado seja um número de endereço válido" - # ) + elif not self.find_numbers(numero): + errors["numero"] = "Certifique-se de que valor informado tenha números" - # if complemento: + elif not self.is_alpha_numeric_character_pattern(numero): + errors["numero"] = ( + "Certifique-se de que valor informado seja um número de endereço válido" + ) - # if len(complemento) < 5 or len(complemento) > 60: - # errors["complemento"] = ( - # "Certifique-se de que o valor tenha entre 5 a 60 caracteres" - # ) + if not cidade: + errors["cidade"] = "Campo cidade obrigatório" - # elif not self.is_alpha_numeric_character_pattern(complemento): - # errors["complemento"] = ( - # "Certifique-se de que o valor tenha apenas caracteres texto" - # ) + if not destino: + errors["destino"] = "Campo destino obrigatório" - # if ponto_referencia: + if not observacao: + errors["observacao"] = "Campo observação obrigatório" - # if len(ponto_referencia) < 5 or len(ponto_referencia) > 60: - # errors["ponto_referencia"] = ( - # "Certifique-se de que o valor tenha entre 5 a 60 caracteres" - # ) + if observacao: - # elif not self.is_alpha_numeric_character_pattern(ponto_referencia): - # errors["ponto_referencia"] = ( - # "Certifique-se de que o valor tenha apenas caracteres texto" - # ) + if len(observacao) < 10 or len(observacao) > 160: + errors["observacao"] = ( + "Certifique-se de que o valor tenha entre 10 a 160 caracteres" + ) if errors: diff --git "a/transportes/migrations/0002_rename_observa\303\247\303\243o_transporte_observacao_and_more.py" "b/transportes/migrations/0002_rename_observa\303\247\303\243o_transporte_observacao_and_more.py" new file mode 100644 index 0000000..764c1f4 --- /dev/null +++ "b/transportes/migrations/0002_rename_observa\303\247\303\243o_transporte_observacao_and_more.py" @@ -0,0 +1,35 @@ +# Generated by Django 5.0.4 on 2024-05-23 18:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("transportes", "0001_initial"), + ] + + operations = [ + migrations.RenameField( + model_name="transporte", + old_name="observação", + new_name="observacao", + ), + migrations.AlterField( + model_name="transporte", + name="motivo_de_transporte", + field=models.IntegerField( + choices=[ + (0, "--Selecione--"), + (1, "Retorno"), + (2, "Exames"), + (3, "Quimioterapia"), + (4, "Internação"), + (5, "Procedimento"), + (6, "Radioterapia"), + (7, "Primeira-Consulta"), + (8, "Outros"), + ] + ), + ), + ] diff --git a/transportes/models.py b/transportes/models.py index e879163..5bdb842 100644 --- a/transportes/models.py +++ b/transportes/models.py @@ -29,7 +29,7 @@ class Transporte(models.Model): observacao = models.CharField(max_length=60) - status = models.IntegerField(choices=STATUS_CHOICES) + status = models.IntegerField(choices=STATUS_CHOICES, default=1) data_criacao = models.DateTimeField(auto_now_add=True) diff --git a/transportes/templates/lista_transportes.html b/transportes/templates/lista_transportes.html index 2a7501f..01411ac 100644 --- a/transportes/templates/lista_transportes.html +++ b/transportes/templates/lista_transportes.html @@ -10,8 +10,39 @@ {% block content %}
+
+

{{ paciente }}

+
+
+ + + + + + + + {% for transporte in transportes %} + + + + + + + + + {% endfor %} +
PacienteData e Hora de ConsultaStatus
{{ transporte.paciente.nome }}{{ transporte.data_de_transporte }} - {{ transporte.horario_de_atendimento }}{{ transporte.status }} + + Editar + + + Cancelar + + + Finalizar +
diff --git a/transportes/templatetags/poll_extras_transportes.py b/transportes/templatetags/poll_extras_transportes.py index 742b973..83df0dd 100644 --- a/transportes/templatetags/poll_extras_transportes.py +++ b/transportes/templatetags/poll_extras_transportes.py @@ -27,7 +27,7 @@ def set_column_input(field: BoundField) -> str: "descricao_motivo": "col-5", "rua": "col-5", "bairro": "col-5", - "numero": "col-5", + "numero": "col-2", "cidade": "col-5", "destino": "col-5", "observacao": "col-5", diff --git a/transportes/urls.py b/transportes/urls.py index 4becb34..9dc56eb 100644 --- a/transportes/urls.py +++ b/transportes/urls.py @@ -3,6 +3,11 @@ urlpatterns = [ path("", views.listar, name="listar_transportes"), + path( + "listar_por_paciente/", + views.listar, + name="listar_por_paciente", + ), path("cadastrar/", views.cadastrar, name="criar_transporte"), path("editar/", views.atualizar, name="editar_transporte"), path("excluir/", views.excluir, name="excluir_transporte"), diff --git a/transportes/views.py b/transportes/views.py index 814e431..c2cd537 100644 --- a/transportes/views.py +++ b/transportes/views.py @@ -10,16 +10,35 @@ def listar(request): context = {} - context["transportes"] = Transporte.objects.all()[:15] + context["transportes"] = Transporte.objects.all() + + return render(request, "lista_transportes.html", context) + + +def listar_por_paciente(request, paciente_id: int): + + context = {} + + transportes: Transporte = Transporte.objects.get(id=paciente_id) + + context["paciente"] = transportes.paciente.nome + + context["transportes"] = transportes + + context["transporte_id"] = transportes.pk return render(request, "lista_transportes.html", context) def cadastrar(request, paciente_id: int): + paciente = Paciente.objects.get(id=paciente_id) + context = {} context["title"] = "Cadastra Transporte" + context["paciente_id"] = paciente.pk + context["nome"] = paciente if request.method == "POST": @@ -30,27 +49,27 @@ def cadastrar(request, paciente_id: int): # print(context["form"].cleaned_data) - context["form"].save() + novo_transporte: Transporte = context["form"].save(commit=False) + + novo_transporte.paciente = paciente - messages.success(request, "Transporte cadastrado com sucesso") + novo_transporte.save() - return redirect("listar_transportes") + # messages.success(request, "Transporte cadastrado com sucesso") - except: + return redirect("listar_por_paciente", paciente_id=paciente.pk) + + except Exception as exc: messages.error( - request, "Ocorreu um erro durante o registo, tente novamente" + request, "Ocorreu um erro durante o registro, tente novamente" ) return render(request, "criar_transporte.html", context) - context["erros"] = context["form"].errors.as_data() + context["errors"] = context["form"].errors.as_data() else: - - paciente = Paciente.objects.get(id=paciente_id) - context["paciente"] = paciente - context["paciente_id"] = paciente.pk context["form"] = TransporteForm() return render(request, "criar_transporte.html", context) diff --git a/validar_hora.py b/validar_hora.py new file mode 100644 index 0000000..509a771 --- /dev/null +++ b/validar_hora.py @@ -0,0 +1,12 @@ +from datetime import datetime, time + +start_time = time(8, 0, 0) +end_time = time(17, 0, 0) + +hora_consulta = time(17, 1, 0) + +if hora_consulta < start_time or hora_consulta > end_time: + + print( + "Erro: Hora informada deve respeitar janela de atendimento, das 08hrs às 17hrs" + )