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">
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/rc_receta_item.xml b/app/src/main/res/layout/rc_receta_item.xml
index d1c0dc4..0cfa962 100644
--- a/app/src/main/res/layout/rc_receta_item.xml
+++ b/app/src/main/res/layout/rc_receta_item.xml
@@ -68,7 +68,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="243dp"
- android:layout_marginTop="13dp"
+ android:layout_marginTop="2dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="10dp"
android:text="Descargar"
@@ -80,6 +80,23 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.487" />
+
+