From 2a21d6b53738920bad7d5125e974583334145a71 Mon Sep 17 00:00:00 2001 From: AngelSuarez03 Date: Sun, 12 May 2024 21:10:34 -0600 Subject: [PATCH] =?UTF-8?q?Inetgraci=C3=B3n=20de=20todas=20las=20funcional?= =?UTF-8?q?idades=20y=20RecycleView=20pacientes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 9 +- .../medicalhealth/AgregarActivity.kt | 3 +- .../medicalhealth/MainActivity.kt | 1 + .../medicalhealth/ModificarActivity.kt | 2 - .../medicalhealth/PacienteActivity.kt | 67 ++++++++ .../medicalhealth/PrincipalActivity.kt | 39 ++--- .../adapters/DoctorDataBaseHelper.kt | 47 ++++++ .../adapters/PacienteViewAdapter.kt | 58 +++++++ app/src/main/res/drawable/account.xml | 9 + app/src/main/res/drawable/doctor.xml | 9 + app/src/main/res/drawable/file_document.xml | 9 + app/src/main/res/drawable/history.xml | 9 + .../main/res/drawable/ic_home_black_24dp.xml | 2 +- app/src/main/res/drawable/plus.xml | 9 + .../main/res/drawable/plus_circle_outline.xml | 9 + .../res/layout/activity_agregar_paciente.xml | 12 -- app/src/main/res/layout/activity_paciente.xml | 47 ++++++ .../main/res/layout/activity_principal.xml | 158 +++++++++++++++--- app/src/main/res/layout/rc_paciente_item.xml | 107 ++++++++++++ 19 files changed, 540 insertions(+), 66 deletions(-) create mode 100644 app/src/main/java/com/terratenientes/medicalhealth/PacienteActivity.kt create mode 100644 app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteViewAdapter.kt create mode 100644 app/src/main/res/drawable/account.xml create mode 100644 app/src/main/res/drawable/doctor.xml create mode 100644 app/src/main/res/drawable/file_document.xml create mode 100644 app/src/main/res/drawable/history.xml create mode 100644 app/src/main/res/drawable/plus.xml create mode 100644 app/src/main/res/drawable/plus_circle_outline.xml create mode 100644 app/src/main/res/layout/activity_paciente.xml create mode 100644 app/src/main/res/layout/rc_paciente_item.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ec0ef92..3e4d4e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools" > @@ -14,7 +14,10 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MedicalHealth" - tools:targetApi="31"> + tools:targetApi="31" > + @@ -48,7 +51,7 @@ android:exported="false" /> + android:exported="true" > diff --git a/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt index 061b0ed..64509c4 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt @@ -30,8 +30,7 @@ class AgregarActivity : AppCompatActivity() { binding.btnConfirmar.setOnClickListener { //db.crearTablaPacientes() agregarPaciente() - val intent = Intent(this@AgregarActivity, EliminarActivity::class.java) - startActivity(intent) + finish() } } private fun agregarPaciente() { diff --git a/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt index e942226..5cb0605 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/MainActivity.kt @@ -27,6 +27,7 @@ class MainActivity : AppCompatActivity() { Toast.makeText(this@MainActivity,"VALIDADO",Toast.LENGTH_LONG).show() val intent = Intent(this@MainActivity, PrincipalActivity::class.java) //intent.putExtra("IDPaciente",binding.tvUsuario.text.toString()) + intent.putExtra("Cedula", binding.tvUsuario.text.toString()) startActivity(intent) }else if(resPaciente==true){ Toast.makeText(this@MainActivity,"VALIDADO",Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt index 58947d5..8d36a40 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/ModificarActivity.kt @@ -35,8 +35,6 @@ class ModificarActivity : AppCompatActivity() { paciente.domicilio = binding.etDomicilio.text.toString() db.modificarPaciente(paciente) finish() - intent = Intent(this@ModificarActivity, ConsultarPacientesActivity::class.java) - startActivity(intent) Toast.makeText(this@ModificarActivity, "Información Actualizada UwU", Toast.LENGTH_LONG).show() } diff --git a/app/src/main/java/com/terratenientes/medicalhealth/PacienteActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/PacienteActivity.kt new file mode 100644 index 0000000..3d9f134 --- /dev/null +++ b/app/src/main/java/com/terratenientes/medicalhealth/PacienteActivity.kt @@ -0,0 +1,67 @@ +package com.terratenientes.medicalhealth + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import androidx.recyclerview.widget.LinearLayoutManager +import com.terratenientes.medicalhealth.adapters.CellClickListener +import com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper +import com.terratenientes.medicalhealth.adapters.PacienteViewAdapter +import com.terratenientes.medicalhealth.adapters.RecetaDataBaseHelper +import com.terratenientes.medicalhealth.adapters.RecetaViewAdapter +import com.terratenientes.medicalhealth.data.Paciente +import com.terratenientes.medicalhealth.data.Receta +import com.terratenientes.medicalhealth.databinding.ActivityPacienteBinding + +class PacienteActivity : AppCompatActivity(), CellClickListener { + lateinit var binding : ActivityPacienteBinding + private var idPaciente : String ="" + private lateinit var db: DoctorDataBaseHelper + private lateinit var recycleAdapter : PacienteViewAdapter + private lateinit var pacientes : List + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityPacienteBinding.inflate(layoutInflater) + val view = binding.root + setContentView(view) + db = DoctorDataBaseHelper(this@PacienteActivity) + pacientes = db.obtenerPacientes() + recycleAdapter = PacienteViewAdapter(pacientes, this@PacienteActivity, this@PacienteActivity) + binding.rvPacientes.layoutManager = LinearLayoutManager(this) + binding.rvPacientes.adapter = recycleAdapter + Log.i("Pacientes", pacientes.toString()) + binding.ivAgregarPaciente.setOnClickListener { + val intent = Intent(this@PacienteActivity, AgregarActivity::class.java) + startActivity(intent) + } + } + + override fun onResume() { + super.onResume() + recycleAdapter.refreshData(db.obtenerPacientes()) + } + + override fun onCellClickListener(position: Int) { + } + + override fun onEliminarClickListener(position: Int) { + val paciente = pacientes[position] + Log.i("Paciente Elim", paciente.toString()) + db.eliminarPaciente(paciente.id) + recycleAdapter.refreshData(db.obtenerPacientes()) + } + + override fun onModifyClickListener(position: Int) { + val paciente = pacientes[position] + val intent = Intent(this@PacienteActivity, ModificarActivity::class.java) + intent.putExtra("Id", paciente.id) + intent.putExtra("Nombre Paciente", paciente.nombre) + intent.putExtra("Apellido Paterno", paciente.apellidoPaterno) + intent.putExtra("Apellido Materno", paciente.apellidoMaterno) + intent.putExtra("Domicilio", paciente.domicilio) + intent.putExtra("Edad", paciente.edad) + intent.putExtra("Sexo", paciente.sexo) + startActivity(intent) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt index f253854..d313efe 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt @@ -3,41 +3,42 @@ package com.terratenientes.medicalhealth import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log +import com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper +import com.terratenientes.medicalhealth.data.Doctor import com.terratenientes.medicalhealth.databinding.ActivityPrincipalBinding +import com.terratenientes.medicalhealth.reports.ConsultarPacientesActivity class PrincipalActivity : AppCompatActivity() { lateinit var binding : ActivityPrincipalBinding + lateinit var db : DoctorDataBaseHelper override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPrincipalBinding.inflate(layoutInflater) val view = binding.root setContentView(view) - - binding.btnAgregarPaciente.setOnClickListener { - val intent = Intent(this@PrincipalActivity, AgregarActivity::class.java) + db = DoctorDataBaseHelper(this@PrincipalActivity) + Log.i("Datos Doctor", intent.getStringExtra("Cedula").toString()) + datosDoctor(intent.getStringExtra("Cedula").toString()) + binding.ivPacientes.setOnClickListener { + val intent = Intent(this@PrincipalActivity, PacienteActivity::class.java) startActivity(intent) } - binding.btnEliminarPaciente.setOnClickListener { - val intent = Intent(this@PrincipalActivity, EliminarActivity::class.java) - startActivity(intent) - } - - binding.btnAgregarReceta.setOnClickListener { + binding.ivRecetas.setOnClickListener { val intent = Intent(this@PrincipalActivity, RecetaActivity::class.java) 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() - } + } + private fun datosDoctor(cedula : String){ + val doctores : List = db.obtenerDoctor(cedula) + val doctor : Doctor = doctores.get(0) + Log.i("Datos Doctor", doctor.toString()) + binding.tvNombreDoctor.setText("Nombre: ${doctor.Nombre}") + binding.tvTelefonoDoctor.setText("Telefono: ${doctor.Telefono}") + binding.tvCedulaDoctor.setText("Cédula: ${doctor.Cedula}") + binding.tvConsultorioDoctor.setText("Consultorio: ${doctor.Consultorio}") } } \ No newline at end of file diff --git a/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt index 2a9745a..9efd040 100644 --- a/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt +++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt @@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import com.terratenientes.medicalhealth.data.Doctor import com.terratenientes.medicalhealth.data.Paciente +import com.terratenientes.medicalhealth.data.Receta class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABASE_NAME,null, DATABASE_VERSION @@ -51,6 +52,7 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA val dropTablePacientes = "DROP TABLE IF EXISTS $TABLE_PACIENTES" db?.execSQL(dropTablePacientes) } + fun crearTablaPacientes(){ val db=writableDatabase val crearTablaPacientes = @@ -73,6 +75,25 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA db.insert(TABLE_NAME,null, values) db.close() } + + @SuppressLint("Range") + fun obtenerDoctor(cedula : String): List{ + val doctores = mutableListOf() + val db = readableDatabase + var cursor = db.rawQuery("SELECT * FROM $TABLE_NAME WHERE $COLUMN_CEDULA = '${cedula}'", null) + while (cursor.moveToNext()) { + val cedula = cursor.getString(cursor.getColumnIndex(COLUMN_CEDULA)) + val nombreDoctor = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE)) + val apellidoDoctor = cursor.getString(cursor.getColumnIndex(COLUMN_APELLIDO)) + val telefonoDoctor = cursor.getString(cursor.getColumnIndex(COLUMN_TELEFONO)) + val consultorioDoctor = cursor.getInt(cursor.getColumnIndex(COLUMN_CONSULTORIO)) + val doctor = Doctor(cedula,nombreDoctor,apellidoDoctor,telefonoDoctor,consultorioDoctor) + doctores.add(doctor) + } + cursor.close() + return doctores + } + fun agregarPaciente(paciente: Paciente) { val db = writableDatabase val values = ContentValues().apply { @@ -88,6 +109,13 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA db.close() } + fun eliminarPaciente(id : Int) : Int{ + val db = writableDatabase + val resultadoEliminacion = db.delete(TABLE_PACIENTES, "$COLUMN_ID_PACIENTE = ?", arrayOf(id.toString())) + db.close() + return resultadoEliminacion + } + fun modificarPaciente(paciente: Paciente){ val db = writableDatabase val values = ContentValues().apply { @@ -165,5 +193,24 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA return edadPaciente } + @SuppressLint("Range") + fun obtenerPacientes(): List{ + val pacientes = mutableListOf() + val db = readableDatabase + val cursor = db.rawQuery("SELECT * FROM ${TABLE_PACIENTES}", null) + while (cursor.moveToNext()) { + val idPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_ID_PACIENTE)) + val nombrePaciente = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE_PACIENTE)) + val apellidoPaterno = cursor.getString(cursor.getColumnIndex(COLUMN_APELLIDO_PATERNO_PACIENTE)) + val apellidoMaterno = cursor.getString(cursor.getColumnIndex(COLUMN_APELLIDO_MATERNO_PACIENTE)) + val edadPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_EDAD)) + val sexoPaciente = cursor.getString(cursor.getColumnIndex(COLUMN_SEXO)) + val domicilioPaciente = cursor.getString(cursor.getColumnIndex(COLUMN_DOMICILIO)) + val paciente = Paciente(idPaciente,nombrePaciente, apellidoPaterno, apellidoMaterno, edadPaciente, sexoPaciente, domicilioPaciente) + pacientes.add(paciente) + } + cursor.close() + return pacientes + } } diff --git a/app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteViewAdapter.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteViewAdapter.kt new file mode 100644 index 0000000..3246706 --- /dev/null +++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteViewAdapter.kt @@ -0,0 +1,58 @@ +package com.terratenientes.medicalhealth.adapters + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.terratenientes.medicalhealth.R +import com.terratenientes.medicalhealth.data.Paciente + +class PacienteViewAdapter (private var notes : List, context: Context, val cellClickListener: CellClickListener) : + RecyclerView.Adapter() { + class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val tvNombre : TextView = itemView.findViewById(R.id.tv_nombre) + val tvApellidoPaterno : TextView = itemView.findViewById(R.id.tv_apellido_paterno) + val tvApellidoMaterno : TextView = itemView.findViewById(R.id.tv_apellido_materno) + val tv_edad : TextView = itemView.findViewById(R.id.tv_edad) + val tv_sexo : TextView = itemView.findViewById(R.id.tv_sexo) + val tv_domicilio : TextView = itemView.findViewById(R.id.tv_domicilio) + val ivModificar : ImageView = itemView.findViewById(R.id.iv_modificar_paciente) + val ivEliminar : ImageView = itemView.findViewById(R.id.iv_eliminar_paciente) + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteViewHolder { + val view = + LayoutInflater.from(parent.context).inflate(R.layout.rc_paciente_item, parent, false) + return NoteViewHolder(view) + } + + override fun getItemCount(): Int { + return notes.size + } + + override fun onBindViewHolder(holder: NoteViewHolder, position: Int) { + val note = notes[position] + holder.tvNombre.text = note.nombre + holder.tvApellidoPaterno.text = note.apellidoPaterno + holder.tvApellidoMaterno.text = note.apellidoMaterno + holder.tv_edad.text = note.edad.toString() + holder.tv_sexo.text = note.sexo + holder.tv_domicilio.text = note.domicilio + + holder.ivEliminar.setOnClickListener { + cellClickListener.onEliminarClickListener(position) + } + holder.ivModificar.setOnClickListener { + cellClickListener.onModifyClickListener(position) + } + } + + fun refreshData(newNotes: List) { + this.notes = newNotes + notifyDataSetChanged() + } + } \ No newline at end of file diff --git a/app/src/main/res/drawable/account.xml b/app/src/main/res/drawable/account.xml new file mode 100644 index 0000000..ab6a90b --- /dev/null +++ b/app/src/main/res/drawable/account.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/doctor.xml b/app/src/main/res/drawable/doctor.xml new file mode 100644 index 0000000..62365b5 --- /dev/null +++ b/app/src/main/res/drawable/doctor.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/file_document.xml b/app/src/main/res/drawable/file_document.xml new file mode 100644 index 0000000..fdab49f --- /dev/null +++ b/app/src/main/res/drawable/file_document.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/history.xml b/app/src/main/res/drawable/history.xml new file mode 100644 index 0000000..9021b3e --- /dev/null +++ b/app/src/main/res/drawable/history.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml index f8bb0b5..e937f55 100644 --- a/app/src/main/res/drawable/ic_home_black_24dp.xml +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/drawable/plus.xml b/app/src/main/res/drawable/plus.xml new file mode 100644 index 0000000..b6d7e26 --- /dev/null +++ b/app/src/main/res/drawable/plus.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/plus_circle_outline.xml b/app/src/main/res/drawable/plus_circle_outline.xml new file mode 100644 index 0000000..4729020 --- /dev/null +++ b/app/src/main/res/drawable/plus_circle_outline.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_agregar_paciente.xml b/app/src/main/res/layout/activity_agregar_paciente.xml index 3753331..01821a2 100644 --- a/app/src/main/res/layout/activity_agregar_paciente.xml +++ b/app/src/main/res/layout/activity_agregar_paciente.xml @@ -114,17 +114,5 @@ android:background="@drawable/radius_btn" android:text="@string/bt_agregar" /> -