From 7edc71a7ffd43174b67c481cd5eaf9d39df90ece Mon Sep 17 00:00:00 2001 From: mosterTeco Date: Sat, 11 May 2024 16:39:01 -0600 Subject: [PATCH] =?UTF-8?q?Funcionalidad=20Eliminar=20Receta=20desde=20el?= =?UTF-8?q?=20m=C3=A9dico=20y=20paciente.=20Funcionalidad=20de=20Cerrar=20?= =?UTF-8?q?Sesi=C3=B3n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../CellClickListener.kt | 6 +-- .../DoctorDataBaseHelper.kt | 8 ++-- .../{Adapters => adapters}/PacienteAdapter.kt | 4 +- .../{Adapters => adapters}/RecetaAdapter.kt | 4 +- .../RecetaDataBaseHelper.kt | 8 ++-- .../RecetaViewAdapter.kt | 10 +++-- .../medicalhealth/AgregarActivity.kt | 4 +- .../medicalhealth/EliminarActivity.kt | 6 +-- .../medicalhealth/EliminarRecetaActivity.kt | 42 +++++++++---------- .../medicalhealth/MainActivity.kt | 6 ++- .../medicalhealth/ModificarActivity.kt | 6 +-- .../PacientePrincipalActivity.kt | 19 +++++---- .../medicalhealth/PrincipalActivity.kt | 11 +++++ .../medicalhealth/RecetaActivity.kt | 8 ++-- .../medicalhealth/RegistrarDActivity.kt | 4 +- app/src/main/java/{Data => data}/Doctor.kt | 2 +- app/src/main/java/{Data => data}/Paciente.kt | 2 +- app/src/main/java/{Data => data}/Receta.kt | 2 +- .../ConsultarPacientesActivity.kt | 8 ++-- .../res/layout/activity_agregar_paciente.xml | 7 ---- .../layout/activity_consultar_pacientes.xml | 2 +- .../main/res/layout/activity_principal.xml | 17 ++++++++ app/src/main/res/layout/rc_receta_item.xml | 19 ++++++++- 24 files changed, 127 insertions(+), 80 deletions(-) rename app/src/main/java/{Adapters => adapters}/CellClickListener.kt (53%) rename app/src/main/java/{Adapters => adapters}/DoctorDataBaseHelper.kt (98%) rename app/src/main/java/{Adapters => adapters}/PacienteAdapter.kt (96%) rename app/src/main/java/{Adapters => adapters}/RecetaAdapter.kt (96%) rename app/src/main/java/{Adapters => adapters}/RecetaDataBaseHelper.kt (96%) rename app/src/main/java/{Adapters => adapters}/RecetaViewAdapter.kt (90%) rename app/src/main/java/{Data => data}/Doctor.kt (90%) rename app/src/main/java/{Data => data}/Paciente.kt (94%) rename app/src/main/java/{Data => data}/Receta.kt (93%) rename app/src/main/java/{Reports => reports}/ConsultarPacientesActivity.kt (98%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1d28abf..d8edc91 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ android:name=".RegistrarDActivity" android:exported="false" /> , context: Context,val c val fechaReceta : TextView = itemView.findViewById(R.id.tv_fecha_receta) val nombreReceta : TextView = itemView.findViewById(R.id.tv_nombre_paciente) val btnDescargar : Button = itemView.findViewById(R.id.btn_descargar_receta) + val btnEliminar: Button = itemView.findViewById(R.id.btn_eliminar_receta) val pesoReceta : TextView = itemView.findViewById(R.id.tv_peso_paciente) val edadReceta : TextView = itemView.findViewById(R.id.tv_edad_paciente) val dosisReceta : TextView=itemView.findViewById(R.id.tv_dosis_medicamento) @@ -47,6 +46,9 @@ class RecetaViewAdapter(private var notes : List, context: Context,val c holder.btnDescargar.setOnClickListener{ cellClickListener.onCellClickListener(position) } + holder.btnEliminar.setOnClickListener{ + cellClickListener.onEliminarClickListener(position) + } } fun refreshData( newNotes : List){ diff --git a/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt index 6f694db..df9d2b5 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt @@ -1,7 +1,7 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Data.Paciente +import adapters.DoctorDataBaseHelper +import data.Paciente import android.R import android.content.Intent import android.os.Bundle diff --git a/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt index 0184ac4..e8d58ef 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt @@ -1,8 +1,8 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Adapters.PacienteAdapter -import Data.Paciente +import adapters.DoctorDataBaseHelper +import adapters.PacienteAdapter +import data.Paciente import android.annotation.SuppressLint import android.os.Bundle import android.widget.Toast diff --git a/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt index 628ce07..90a746b 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt @@ -1,24 +1,20 @@ package com.terratenientes.medicalhealth -import Adapters.RecetaAdapter -import Adapters.RecetaDataBaseHelper -import Data.Receta +import adapters.RecetaAdapter +import adapters.RecetaDataBaseHelper +import data.Receta import android.os.Bundle import android.widget.Toast -import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat -import com.terratenientes.medicalhealth.databinding.ActivityEliminarPacienteBinding import com.terratenientes.medicalhealth.databinding.ActivityEliminarRecetaBinding import android.widget.ListView - class EliminarRecetaActivity : AppCompatActivity() { private lateinit var binding: ActivityEliminarRecetaBinding private lateinit var dbReceta: RecetaDataBaseHelper private lateinit var recetaAdapter: RecetaAdapter + private var recetaSeleccionada: Receta? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -28,18 +24,16 @@ class EliminarRecetaActivity : AppCompatActivity() { dbReceta = RecetaDataBaseHelper(this) - // Configurar el ListView y el adaptador - val recetas = obtenerListaRecetas() - recetaAdapter = RecetaAdapter(this, recetas) - binding.listaRecetas.adapter = recetaAdapter + cargarListaRecetas() + + binding.listaRecetas.setOnItemClickListener { _, _, position, _ -> + recetaSeleccionada = recetaAdapter.getItem(position) + } - // Manejar el evento de clic en el botón para eliminar receta binding.btnEliminarReceta.setOnClickListener { - val posicionSeleccionada = binding.listaRecetas.selectedItemPosition - if (posicionSeleccionada != ListView.INVALID_POSITION) { - val recetaSeleccionada = recetas[posicionSeleccionada] - eliminarReceta(recetaSeleccionada) - recetaAdapter.remove(recetaSeleccionada) + if (recetaSeleccionada != null) { + eliminarReceta(recetaSeleccionada!!) + cargarListaRecetas() Toast.makeText(this, "Receta eliminada correctamente", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this, "Por favor, seleccione una receta para eliminar", Toast.LENGTH_SHORT).show() @@ -47,11 +41,17 @@ class EliminarRecetaActivity : AppCompatActivity() { } } + private fun cargarListaRecetas() { + val recetas = obtenerListaRecetas() + recetaAdapter = RecetaAdapter(this, recetas) + binding.listaRecetas.adapter = recetaAdapter + } + private fun obtenerListaRecetas(): List { - return dbReceta.obtenerTodasRecetas() // Implementa este método en tu RecetaDataBaseHelper para obtener todas las recetas + return dbReceta.obtenerTodasRecetas() } private fun eliminarReceta(receta: Receta) { - dbReceta.eliminarReceta(receta) // Implementa este método en tu RecetaDataBaseHelper para eliminar una receta + dbReceta.eliminarReceta(receta) } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt index 9493193..7e8d24e 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt @@ -1,7 +1,7 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Data.Doctor +import adapters.DoctorDataBaseHelper +import data.Doctor import android.annotation.SuppressLint import android.content.Intent import androidx.appcompat.app.AppCompatActivity @@ -41,6 +41,8 @@ class MainActivity : AppCompatActivity() { val intent = Intent(this@MainActivity, RegistrarDActivity::class.java) startActivity(intent) } + + } @SuppressLint("SuspiciousIndentation") private fun cargarDatos(){ diff --git a/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt index 231341e..e5e8dab 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt @@ -1,8 +1,8 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Data.Paciente -import Reports.ConsultarPacientesActivity +import adapters.DoctorDataBaseHelper +import data.Paciente +import reports.ConsultarPacientesActivity import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle diff --git a/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt index b3cbd7c..13e3f8c 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt @@ -1,14 +1,11 @@ package com.terratenientes.medicalhealth -import Adapters.CellClickListener -import Adapters.RecetaDataBaseHelper -import Adapters.RecetaViewAdapter -import Data.Receta +import adapters.CellClickListener +import adapters.RecetaDataBaseHelper +import adapters.RecetaViewAdapter +import data.Receta import android.Manifest import android.content.pm.PackageManager -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.Paint import android.graphics.Typeface import android.graphics.pdf.PdfDocument import android.os.Bundle @@ -76,6 +73,14 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener { pedirPermisosPDF() } } + + override fun onEliminarClickListener(position: Int) { + val receta = recetas[position] + db.eliminarReceta(receta) + recycleAdapter.refreshData(db.obtenerRecetasPaciente(idPaciente)) + Toast.makeText(this, "Receta eliminada correctamente", Toast.LENGTH_SHORT).show() + } + // función que valida si los permisos ya estan garantizados por parte del usuario fun permisosPDF() : Boolean{ val permission1= ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) diff --git a/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt index d325b95..f253854 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt @@ -28,5 +28,16 @@ class PrincipalActivity : AppCompatActivity() { startActivity(intent) } + binding.btnEliminarReceta.setOnClickListener { + val intent = Intent (this@PrincipalActivity, EliminarRecetaActivity::class.java) + startActivity(intent) + } + + binding.btnCerrar.setOnClickListener { + val intent = Intent(this@PrincipalActivity, MainActivity::class.java) + startActivity(intent) + finish() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/terratenientes/medicalhealth/RecetaActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/RecetaActivity.kt index a3d3d9d..b098784 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/RecetaActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/RecetaActivity.kt @@ -1,8 +1,8 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Adapters.RecetaDataBaseHelper -import Data.Receta +import adapters.DoctorDataBaseHelper +import adapters.RecetaDataBaseHelper +import data.Receta import android.annotation.SuppressLint import android.os.Bundle import android.view.View @@ -27,7 +27,7 @@ class RecetaActivity : AppCompatActivity(), OnItemSelectedListener { db= RecetaDataBaseHelper(this@RecetaActivity) dbPaciente = DoctorDataBaseHelper(this@RecetaActivity) setContentView(view) - // db.crearTablaReceta() + //db.crearTablaReceta() cargarSpinnerPacientes() binding.spNombrePaciente.onItemSelectedListener=this binding.btnAgregarReceta.setOnClickListener { diff --git a/app/src/main/java/com/terratenientes/medicalhealth/RegistrarDActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/RegistrarDActivity.kt index 07f5f96..80d7801 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/RegistrarDActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/RegistrarDActivity.kt @@ -1,7 +1,7 @@ package com.terratenientes.medicalhealth -import Adapters.DoctorDataBaseHelper -import Data.Doctor +import adapters.DoctorDataBaseHelper +import data.Doctor import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity diff --git a/app/src/main/java/Data/Doctor.kt b/app/src/main/java/data/Doctor.kt similarity index 90% rename from app/src/main/java/Data/Doctor.kt rename to app/src/main/java/data/Doctor.kt index 9138c25..72dafb6 100644 --- a/app/src/main/java/Data/Doctor.kt +++ b/app/src/main/java/data/Doctor.kt @@ -1,3 +1,3 @@ -package Data +package data data class Doctor(var Cedula : String ,var Nombre : String, var Apellido : String, var Telefono : String, var Consultorio : Int) diff --git a/app/src/main/java/Data/Paciente.kt b/app/src/main/java/data/Paciente.kt similarity index 94% rename from app/src/main/java/Data/Paciente.kt rename to app/src/main/java/data/Paciente.kt index 7db0a88..ca33451 100644 --- a/app/src/main/java/Data/Paciente.kt +++ b/app/src/main/java/data/Paciente.kt @@ -1,4 +1,4 @@ -package Data +package data data class Paciente( var id: Int, // Este campo representa el ID autoincrementable en la base de datos diff --git a/app/src/main/java/Data/Receta.kt b/app/src/main/java/data/Receta.kt similarity index 93% rename from app/src/main/java/Data/Receta.kt rename to app/src/main/java/data/Receta.kt index 22fab2c..ace1073 100644 --- a/app/src/main/java/Data/Receta.kt +++ b/app/src/main/java/data/Receta.kt @@ -1,3 +1,3 @@ -package Data +package data data class Receta(var NombrePaciente : String, var edadPaciente : Int, var pesoPaciente: Double, var nombreMedicamento : String, var fecha : String, var dosis : String, var duracion :String) diff --git a/app/src/main/java/Reports/ConsultarPacientesActivity.kt b/app/src/main/java/reports/ConsultarPacientesActivity.kt similarity index 98% rename from app/src/main/java/Reports/ConsultarPacientesActivity.kt rename to app/src/main/java/reports/ConsultarPacientesActivity.kt index d393697..54b6dc4 100644 --- a/app/src/main/java/Reports/ConsultarPacientesActivity.kt +++ b/app/src/main/java/reports/ConsultarPacientesActivity.kt @@ -1,4 +1,4 @@ -package Reports +package reports import android.Manifest import android.annotation.SuppressLint @@ -11,10 +11,10 @@ import android.os.Environment import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat -import Adapters.DoctorDataBaseHelper +import adapters.DoctorDataBaseHelper import com.terratenientes.medicalhealth.ModificarActivity -import Data.Paciente -import Adapters.PacienteAdapter +import data.Paciente +import adapters.PacienteAdapter import com.terratenientes.medicalhealth.R import com.terratenientes.medicalhealth.databinding.ActivityConsultarPacientesBinding import java.io.File diff --git a/app/src/main/res/layout/activity_agregar_paciente.xml b/app/src/main/res/layout/activity_agregar_paciente.xml index 980949c..3753331 100644 --- a/app/src/main/res/layout/activity_agregar_paciente.xml +++ b/app/src/main/res/layout/activity_agregar_paciente.xml @@ -18,13 +18,6 @@ android:gravity="center" /> - - + tools:context="reports.ConsultarPacientesActivity"> +