From 6169388fef54207ce5279ec693b95ec12331b1ca Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 10 Jul 2020 11:27:00 +0200 Subject: [PATCH] Update patient edit form region and city dialogs --- src/database.php | 12 +++++++++--- src/patient_edit_form.php | 32 ++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/database.php b/src/database.php index e5d7827..0ad8243 100644 --- a/src/database.php +++ b/src/database.php @@ -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"], diff --git a/src/patient_edit_form.php b/src/patient_edit_form.php index 86eef25..b719838 100644 --- a/src/patient_edit_form.php +++ b/src/patient_edit_form.php @@ -6,6 +6,10 @@ + + + + @@ -14,8 +18,10 @@ $pdo = connectDatabase(); $data = fetchPatientData($pdo, $_GET["edit"]); + $countries = fetchCountries($pdo); + $regions = fetchRegions($pdo); ?> -
+
@@ -44,16 +50,30 @@
- - + +
- + +
- - + + +