Update patient edit form region and city dialogs

This commit is contained in:
coolneng 2020-07-10 11:27:00 +02:00
parent 01902f3757
commit 6169388fef
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 35 additions and 9 deletions

View File

@ -42,9 +42,9 @@ function fetchLatestCity($pdo){
function createRegion($pdo, $data){
$query = "INSERT INTO provincias (id_provincia, provincia) VALUES (?,?)";
$row = fetchLatestRegion($pdo);
$index = $row["id_provincia"];
$next_index = $index + 1;
$pdo->prepare($query)->execute([$next_index, $data["provincia2"]]);
$last_region = $row["id_provincia"];
$index = $last_region + 1;
$pdo->prepare($query)->execute([$index, $data["provincia2"]]);
return $index;
}
@ -76,6 +76,12 @@ function editPatient($pdo, $data, $id)
{
$query = "UPDATE paciente SET nombre=?, apellido=?, fecha_de_nacimiento=?, documento_identificativo=?,
tipo_documento=?, direccion=?, localidad=?, provincia=?, pais=? WHERE id=?";
if($data["provincia"] == "empty" and $data["localidad"] == "empty"){
$region = createRegion($pdo, $data);
$city = createCity($pdo, $data, $region);
$data["provincia"] = $region;
$data["localidad"] = $city;
}
$result = $pdo->prepare($query);
$result->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"],
$data["documento_identificativo"], $data["tipo_documento"], $data["direccion"],

View File

@ -6,6 +6,10 @@
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" />
<script src="static/jquery-3.5.1.min.js"></script>
<script src="ajax.js"></script>
<script src="validate_patient.js"></script>
<script src="change_input_type.js"></script>
</head>
<body>
<?php include 'navbar.php'; ?>
@ -14,8 +18,10 @@
$pdo = connectDatabase();
$data = fetchPatientData($pdo, $_GET["edit"]);
$countries = fetchCountries($pdo);
$regions = fetchRegions($pdo);
?>
<form method="post" action="patient_management.php">
<form method="post" action="patient_management.php" onsubmit="return validatePatient();">
<div class="input-group">
<label>Nombre</label>
<input type="text" name="nombre" value="<?php echo $data[1]; ?>">
@ -44,16 +50,30 @@
<input type="text" name="direccion" value="<?php echo $data[6]; ?>">
</div>
<div class="input-group">
<label>localidad</label>
<input type="text" name="localidad" value="<?php echo $data[7]; ?>">
<label>pais</label>
<select id="pais" name="pais" onchange="changeInputType();">
<option>Selecciona el país</option>
<?php foreach ($countries as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[2]; ?></option>
<?php endforeach ?>
</select>
</div>
<div class="input-group">
<label>provincia</label>
<input type="text" name="provincia" value="<?php echo $data[8]; ?>">
<select id="provincia" name="provincia">
<option value="empty">Selecciona la provincia</option>
<?php foreach ($regions as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select>
<input type="hidden" id="provincia2" name="provincia2" value="">
</div>
<div class="input-group">
<label>pais</label>
<input type="text" name="pais" value="<?php echo $data[9]; ?>">
<label>localidad</label>
<select id="localidad" name="localidad">
<option value="empty">Selecciona la localidad</option>
</select>
<input type="hidden" id="localidad2" name="localidad2" value="">
</div>
<div class="input-group">
<button class="btn" type="submit" name="edit" >Editar</button>