filtros fecha nombre
This commit is contained in:
		| @ -28,7 +28,10 @@ defmodule DerivantesWeb.DerivantesLive do | ||||
| 						class="flex items-stretch" | ||||
|         	> | ||||
|           	<.input field={@filters[:dni]} type="text" placeholder="Documento del paciente"/> | ||||
|           	<.input field={@filters[:accession]} type="text" placeholder="Accession number"/> | ||||
|           	<.input field={@filters[:nombre]} type="text" placeholder="Nombre del paciente"/> | ||||
|           	<.input field={@filters[:apellido]} type="text" placeholder="Apellido del paciente"/> | ||||
|           	<.input field={@filters[:fecha]} type="date"/> | ||||
|  | ||||
| 						<br> | ||||
|           	<:actions> | ||||
|             	<.button class="w-full"> | ||||
| @ -107,20 +110,32 @@ defmodule DerivantesWeb.DerivantesLive do | ||||
|   def get_studies(socket, filter) do | ||||
|  | ||||
|   	keys = Map.keys(filter) | ||||
|   	IO.inspect(keys) | ||||
|   	mat_filter = dynamic([vl], vl.matder == ^socket.assigns.current_user.matricula) | ||||
|   	filter_conditions = | ||||
|     	Enum.reduce(keys, mat_filter, fn v, filter_conditions -> | ||||
|       	case v do | ||||
|         	"dni" -> | ||||
|           	if(filter["dni"] != "") do | ||||
|             	dynamic([vl], vl.tipo_documento == ^filter["dni"] and ^filter_conditions) | ||||
| 							dni_with_du = "DU" <> filter["dni"] | ||||
|             	dynamic([vl], vl.tipo_documento == ^dni_with_du and ^filter_conditions) | ||||
|           	else | ||||
|             	filter_conditions | ||||
|           	end | ||||
|         	"accession" -> | ||||
|           	if(filter["accession"] != "") do | ||||
|             	dynamic([vl], vl.accessionnumber == ^filter["accession"] and ^filter_conditions) | ||||
|         	"nombre" -> | ||||
|           	if(filter["nombre"] != "") do | ||||
|             	dynamic([vl], vl.patientfirstname == ^filter["nombre"] and ^filter_conditions) | ||||
|           	else | ||||
|             	filter_conditions | ||||
|           	end | ||||
|         	"apellido" -> | ||||
|           	if(filter["apellido"] != "") do | ||||
|             	dynamic([vl], vl.patientlastname == ^filter["apellido"] and ^filter_conditions) | ||||
|           	else | ||||
|             	filter_conditions | ||||
|           	end | ||||
| 						"fecha" -> | ||||
|           	if(filter["fecha"] != "") do | ||||
|             	dynamic([vl], vl.start_date == ^String.replace(filter["fecha"], "-", "") and ^filter_conditions) | ||||
|           	else | ||||
|             	filter_conditions | ||||
|           	end | ||||
|  | ||||
		Reference in New Issue
	
	Block a user