diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index ab80313..0c0c338 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -3,20 +3,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 8e3077e..e562c0c 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -51,6 +51,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation("androidx.navigation:navigation-fragment-ktx:2.6.0")
+ implementation("com.dmitryborodin:pdfview-android:1.1.0")
implementation("androidx.navigation:navigation-ui-ktx:2.6.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b61de05..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,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MedicalHealth"
- tools:targetApi="31">
+ tools:targetApi="31" >
+
+
+
@@ -29,7 +38,7 @@
android:name=".RegistrarDActivity"
android:exported="false" />
+ android:exported="true" >
diff --git a/app/src/main/java/Data/Receta.kt b/app/src/main/java/Data/Receta.kt
deleted file mode 100644
index d31a06c..0000000
--- a/app/src/main/java/Data/Receta.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package Data
-
-data class Receta(val NombrePaciente : String, val edadPaciente : Int, val pesoPaciente: Double, val nombreMedicamento : String, val fecha : String, val dosis : String, val duracion :String)
diff --git a/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/AgregarActivity.kt
index 6f694db..64509c4 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 com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.data.Paciente
import android.R
import android.content.Intent
import android.os.Bundle
@@ -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/EliminarActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt
index 0184ac4..7ff6004 100644
--- a/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/EliminarActivity.kt
@@ -1,9 +1,10 @@
package com.terratenientes.medicalhealth
-import Adapters.DoctorDataBaseHelper
-import Adapters.PacienteAdapter
-import Data.Paciente
+import com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.adapters.PacienteAdapter
+import com.terratenientes.medicalhealth.data.Paciente
import android.annotation.SuppressLint
+import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
@@ -38,6 +39,12 @@ class EliminarActivity : AppCompatActivity() {
Toast.makeText(this, "Por favor, selecciona un paciente para eliminar.", Toast.LENGTH_SHORT).show()
}
}
+
+ binding.btnCancelar.setOnClickListener {
+ val intent = Intent(this@EliminarActivity, PrincipalActivity::class.java)
+ startActivity(intent)
+ finish()
+ }
}
private fun cargarListaPacientes() {
diff --git a/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt
index 628ce07..530fa82 100644
--- a/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/EliminarRecetaActivity.kt
@@ -1,24 +1,21 @@
package com.terratenientes.medicalhealth
-import Adapters.RecetaAdapter
-import Adapters.RecetaDataBaseHelper
-import Data.Receta
+import com.terratenientes.medicalhealth.adapters.RecetaAdapter
+import com.terratenientes.medicalhealth.adapters.RecetaDataBaseHelper
+import android.content.Intent
+import com.terratenientes.medicalhealth.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,30 +25,41 @@ 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()
}
}
+
+ binding.btnCancelarr.setOnClickListener {
+ val intent = Intent(this@EliminarRecetaActivity, PrincipalActivity::class.java)
+ startActivity(intent)
+ finish()
+ }
+
+ }
+
+ 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 ef65f3b..5cb0605 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 com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.data.Doctor
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
@@ -19,11 +19,20 @@ class MainActivity : AppCompatActivity() {
setContentView(view)
db = DoctorDataBaseHelper(this@MainActivity)
+ //db.createTable()
binding.btnIniciarSesion.setOnClickListener {
var res=db.validarDatos(binding.tvUsuario.text.toString(),binding.tvContrasena.text.toString())
+ var resPaciente = db.validarDatosPaciente(binding.tvUsuario.text.toString(), binding.tvContrasena.text.toString())
if(res==true){
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()
+ val intent = Intent(this@MainActivity, PacientePrincipalActivity::class.java)
+ intent.putExtra("IDPaciente",binding.tvContrasena.text.toString())
startActivity(intent)
}else{
Toast.makeText(this@MainActivity," NO VALIDADO",Toast.LENGTH_LONG).show()
@@ -33,6 +42,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..8d36a40 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 com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.data.Paciente
+import com.terratenientes.medicalhealth.reports.ConsultarPacientesActivity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
@@ -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/ModificarRecetaActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/ModificarRecetaActivity.kt
new file mode 100644
index 0000000..9673499
--- /dev/null
+++ b/app/src/main/java/com/terratenientes/medicalhealth/ModificarRecetaActivity.kt
@@ -0,0 +1,49 @@
+package com.terratenientes.medicalhealth
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.util.Log
+import com.terratenientes.medicalhealth.adapters.RecetaDataBaseHelper
+import com.terratenientes.medicalhealth.data.Receta
+import com.terratenientes.medicalhealth.databinding.ActivityModificarRecetaBinding
+
+class ModificarRecetaActivity : AppCompatActivity() {
+ lateinit var binding : ActivityModificarRecetaBinding
+ lateinit var receta : Receta
+ lateinit var db : RecetaDataBaseHelper
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityModificarRecetaBinding.inflate(layoutInflater)
+ val view = binding.root
+ setContentView(view)
+ db = RecetaDataBaseHelper(this@ModificarRecetaActivity)
+ receta = Receta(intent.getStringExtra("NombrePaciente").toString(),intent.getStringExtra("EdadPaciente").toString().toInt(),intent.getStringExtra("PesoPaciente").toString().toDouble(),intent.getStringExtra("NombreMedicamento").toString(),intent.getStringExtra("Fecha").toString(),intent.getStringExtra("Dosis").toString(), intent.getStringExtra("Duracion").toString())
+ llenarCampos(receta)
+ binding.btnModificarReceta.setOnClickListener {
+ modificarReceta(receta)
+ }
+ }
+
+ private fun modificarReceta(receta : Receta) : Unit {
+ Log.i("Info Recibida", receta.toString())
+ receta.edadPaciente = binding.etEdadPaciente.text.toString().toInt()
+ receta.pesoPaciente = binding.etPesoPaciente.text.toString().toDouble()
+ receta.nombreMedicamento = binding.etRecetaMedicamento.text.toString()
+ receta.fecha = binding.etFecha.text.toString()
+ receta.dosis = binding.etDosisMedicamento.text.toString()
+ receta.duracion = binding.etDuracion.text.toString()
+ db.modificarReceta(receta)
+ Log.i("Info Actualizada", receta.toString())
+ finish()
+ }
+
+ private fun llenarCampos(receta : Receta) : Unit {
+ binding.tvNombrePaciente.setText(receta.NombrePaciente)
+ binding.etEdadPaciente.setText(receta.edadPaciente.toString())
+ binding.etPesoPaciente.setText(receta.pesoPaciente.toString())
+ binding.etRecetaMedicamento.setText(receta.nombreMedicamento)
+ binding.etFecha.setText(receta.fecha)
+ binding.etDosisMedicamento.setText(receta.dosis)
+ binding.etDuracion.setText(receta.duracion)
+ }
+}
\ No newline at end of file
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/PacientePrincipalActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt
new file mode 100644
index 0000000..65e5781
--- /dev/null
+++ b/app/src/main/java/com/terratenientes/medicalhealth/PacientePrincipalActivity.kt
@@ -0,0 +1,174 @@
+package com.terratenientes.medicalhealth
+
+import com.terratenientes.medicalhealth.adapters.CellClickListener
+import com.terratenientes.medicalhealth.adapters.RecetaDataBaseHelper
+import com.terratenientes.medicalhealth.adapters.RecetaViewAdapter
+import com.terratenientes.medicalhealth.data.Receta
+import android.Manifest
+import android.content.Intent
+import android.content.pm.PackageManager
+import android.graphics.Typeface
+import android.graphics.pdf.PdfDocument
+import android.os.Bundle
+import android.os.Environment
+import android.text.TextPaint
+import android.util.Log
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.app.ActivityCompat
+import androidx.core.content.ContextCompat
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.terratenientes.medicalhealth.databinding.ActivityPacientePrincipalBinding
+import java.io.File
+import java.io.FileOutputStream
+
+class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
+ private lateinit var binding: ActivityPacientePrincipalBinding
+ private var idPaciente : String =""
+ private lateinit var db: RecetaDataBaseHelper
+ private lateinit var recycleAdapter : RecetaViewAdapter
+ private lateinit var recetas : List
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityPacientePrincipalBinding.inflate(layoutInflater)
+ val view = binding.root
+ setContentView(view)
+ idPaciente= intent.getStringExtra("IDPaciente")!!
+ db= RecetaDataBaseHelper(this)
+ recetas=db.obtenerRecetasPaciente(idPaciente)
+
+ recycleAdapter = RecetaViewAdapter(db.obtenerRecetasPaciente(idPaciente), this, this@PacientePrincipalActivity)
+
+ binding.rvRecetasPaciente.layoutManager=LinearLayoutManager(this)
+ binding.rvRecetasPaciente.adapter= recycleAdapter
+ }
+
+ override fun onResume() {
+ super.onResume()
+ recycleAdapter.refreshData(db.obtenerRecetasPaciente(idPaciente))
+ }
+
+ override fun onCellClickListener(position: Int) {
+ val datosPaciente = db.obtenerRecetasPaciente(idPaciente)//ARREGLO DE TODAS LAS RECETAS DEL PACIENTE
+ //Toast.makeText(this, "Peso : ${datosPaciente[position].pesoPaciente}+ edad: ${datosPaciente[position].edadPaciente} ", Toast.LENGTH_LONG).show()
+ val receta = recetas[position]
+ val nombrePaciente = recetas[position].NombrePaciente
+ val nombreMeciamento=recetas[position].nombreMedicamento
+ val dosisMedicamento = recetas[position].dosis
+ val duracionMedicamento = recetas[position].duracion
+ val fechaReceta = recetas[position].fecha
+ val pesoPaciente= recetas[position].pesoPaciente
+ val edadPaciente = recetas[position].edadPaciente
+ val descripcionReceta ="Fecha de Consulta: ${fechaReceta}\n" +
+ "Datos Generales del Paciente : \n " +
+ "Peso del Paciente : ${pesoPaciente}\n" +
+ "Edad del Paciente : ${edadPaciente}" +
+ "Medicamento a Recetar: ${nombreMeciamento}\n Dosis del Medicamento : ${dosisMedicamento}\n" +
+ "Duración del Tratamiento ${duracionMedicamento} \n"
+
+
+ if(permisosPDF()){
+ // Toast.makeText(this, "Peso : ${datosPaciente[position].pesoPaciente}+ edad: ${datosPaciente[position].edadPaciente} ", Toast.LENGTH_LONG).show()
+ //Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
+ generarPDF(nombrePaciente, descripcionReceta, nombreMeciamento)
+ }else{
+ 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()
+ }
+
+ override fun onModifyClickListener(position: Int) {
+ val receta = recetas[position]
+ Log.i("Prueba Modificar", receta.toString())
+ val intent = Intent(this@PacientePrincipalActivity, ModificarRecetaActivity::class.java)
+ intent.putExtra("NombrePaciente", receta.NombrePaciente)
+ intent.putExtra("EdadPaciente", receta.edadPaciente.toString())
+ intent.putExtra("PesoPaciente", receta.pesoPaciente.toString())
+ intent.putExtra("NombreMedicamento", receta.nombreMedicamento)
+ intent.putExtra("Fecha", receta.fecha)
+ intent.putExtra("Dosis", receta.dosis)
+ intent.putExtra("Duracion", receta.duracion)
+ startActivity(intent)
+ }
+
+ // 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)
+ val permission2= ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
+
+ return permission1 == PackageManager.PERMISSION_GRANTED && permission2 == PackageManager.PERMISSION_GRANTED
+ }
+ fun pedirPermisosPDF(){
+ ActivityCompat.requestPermissions(this,
+ arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_EXTERNAL_STORAGE
+ ),200)
+ }
+
+ fun generarPDF(tituloReceta : String, contenidoReceta : String, medicamento : String){
+ if (!permisosPDF()) {
+ pedirPermisosPDF()
+ return
+ }
+ val pdfDoducment = PdfDocument()
+ val tituloPDF = TextPaint()
+ val contenido = TextPaint()
+ val paginaInfo = PdfDocument.PageInfo.Builder(816,1054,1).create()
+ val paginaReceta = pdfDoducment.startPage(paginaInfo)
+
+ val canvas = paginaReceta.canvas
+ tituloPDF.typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
+ tituloPDF.textSize=30f
+ canvas.drawText(tituloReceta,10f,150f,tituloPDF)
+
+ contenido.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
+ tituloPDF.textSize=20f
+ val arrayContenido = contenidoReceta.split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+ var y=200
+ for(i in arrayContenido.indices){
+ canvas.drawText(arrayContenido[i],20f,y.toFloat(),contenido)
+ y=y+15
+ }
+ pdfDoducment.finishPage(paginaReceta)
+ val directory = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
+ val file=File(directory,"Receta${medicamento}.pdf")
+ try {
+ pdfDoducment.writeTo(FileOutputStream(file))
+ Toast.makeText(this,"PDF CREADO CORRECTAMENTE",Toast.LENGTH_LONG).show()
+ }catch (e: Exception){
+ Toast.makeText(this,"ERROR CREAR PDF ${e.toString()}",Toast.LENGTH_LONG).show()
+
+ }
+ pdfDoducment.close()
+ }
+
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ if(requestCode==200){
+ if(grantResults.isNotEmpty() && grantResults.all { it == PackageManager.PERMISSION_GRANTED }){
+ val writeStorage = grantResults[0]==PackageManager.PERMISSION_GRANTED
+ val readStorage = grantResults[1]==PackageManager.PERMISSION_GRANTED
+ //generarPDF("Título", "Contenido")
+ if(writeStorage && readStorage){
+ Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
+ }else{
+ Toast.makeText(this@PacientePrincipalActivity, "PERMISOS DENEGADOS", Toast.LENGTH_SHORT).show()
+ finish()
+ }
+ }
+ }
+ }
+
+
+}
\ 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 d325b95..d313efe 100644
--- a/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/PrincipalActivity.kt
@@ -3,30 +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)
}
}
+
+ 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/RecetaActivity.kt b/app/src/main/java/com/terratenientes/medicalhealth/RecetaActivity.kt
index b539aeb..aad1018 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 com.terratenientes.medicalhealth.adapters.RecetaDataBaseHelper
+import com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.data.Receta
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
@@ -27,6 +27,7 @@ class RecetaActivity : AppCompatActivity(), OnItemSelectedListener {
db= RecetaDataBaseHelper(this@RecetaActivity)
dbPaciente = DoctorDataBaseHelper(this@RecetaActivity)
setContentView(view)
+ //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..3d83802 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 com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
+import com.terratenientes.medicalhealth.data.Doctor
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
diff --git a/app/src/main/java/com/terratenientes/medicalhealth/adapters/CellClickListener.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/CellClickListener.kt
new file mode 100644
index 0000000..2bac3d5
--- /dev/null
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/CellClickListener.kt
@@ -0,0 +1,7 @@
+package com.terratenientes.medicalhealth.adapters
+
+interface CellClickListener {
+ fun onCellClickListener(position : Int)
+ fun onEliminarClickListener(position: Int)
+ fun onModifyClickListener(position: Int)
+}
\ No newline at end of file
diff --git a/app/src/main/java/Adapters/DoctorDataBaseHelper.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt
similarity index 57%
rename from app/src/main/java/Adapters/DoctorDataBaseHelper.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt
index 8c97e4d..9efd040 100644
--- a/app/src/main/java/Adapters/DoctorDataBaseHelper.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/DoctorDataBaseHelper.kt
@@ -1,12 +1,13 @@
-package Adapters
+package com.terratenientes.medicalhealth.adapters
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
-import Data.Doctor
-import Data.Paciente
+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 {
@@ -84,9 +105,17 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
put(COLUMN_DOMICILIO, paciente.domicilio)
}
db.insert(TABLE_PACIENTES, null, values)
+ print("ID DEL PACIENTE AGREGADO: "+ COLUMN_ID_PACIENTE)
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 {
@@ -114,16 +143,43 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
val dropQuery="DROP TABLE IF EXISTS $TABLE_NAME"
db?.execSQL(dropQuery)
}
- fun validarDatos(cedula :String , contrasena : String): Boolean{
+
+ fun validarDatos(usuario :String , contrasena : String): Boolean{
val db = readableDatabase
- val validarQuery = "SELECT * FROM $TABLE_NAME WHERE $COLUMN_CEDULA = '$cedula' AND $COLUMN_CONTRASENA = '$contrasena'"
+ val validarQuery = "SELECT $COLUMN_CEDULA,$COLUMN_CONTRASENA FROM $TABLE_NAME WHERE $COLUMN_CEDULA = '$usuario' AND $COLUMN_CONTRASENA = '$contrasena' "
val cursor = db.rawQuery(validarQuery, null)
val isValid = cursor.count > 0
cursor.close()
return isValid
}
+ @SuppressLint("Range")
+ fun seleccionarDoctores(): List{
+ val doctores= mutableListOf()
+ val db= readableDatabase
+ val query="SELECT * FROM $TABLE_NAME "
+ val cursor=db.query(TABLE_NAME,null,null,null,null,null,null)
+ while (cursor.moveToNext()){
+ val cedula=cursor.getString(cursor.getColumnIndex(COLUMN_CEDULA))
+ val nombre=cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE))
+ val apellido=cursor.getString(cursor.getColumnIndex(COLUMN_APELLIDO))
+ val telefono = cursor.getString(cursor.getColumnIndex(COLUMN_TELEFONO))
+ val consultorio=cursor.getInt(cursor.getColumnIndex(COLUMN_CONSULTORIO))
+ val contrasena=cursor.getString(cursor.getColumnIndex(COLUMN_CONTRASENA))
+ val doctor = Doctor(cedula,nombre,apellido,telefono,consultorio)
+ doctores.add(doctor)
+ }
+ return doctores
+ }
- fun edadPaciente(nombrePaciente : String) : Int{
+ fun validarDatosPaciente(usuario : String, contrasena: String): Boolean{
+ val db = readableDatabase
+ val validarQuery = "SELECT $COLUMN_ID_PACIENTE,$COLUMN_NOMBRE_PACIENTE FROM $TABLE_PACIENTES WHERE $COLUMN_ID_PACIENTE = '$usuario' AND $COLUMN_NOMBRE_PACIENTE = '$contrasena' "
+ val cursor = db.rawQuery(validarQuery, null)
+ val isValid = cursor.count > 0
+ cursor.close()
+ return isValid
+ }
+ fun edadPaciente(nombrePaciente : String) : Int{
val db=readableDatabase
var edadPaciente =0
val queryEdad= "SELECT $COLUMN_EDAD FROM $TABLE_PACIENTES WHERE $COLUMN_NOMBRE_PACIENTE='${nombrePaciente}'"
@@ -137,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/Adapters/PacienteAdapter.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteAdapter.kt
similarity index 91%
rename from app/src/main/java/Adapters/PacienteAdapter.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteAdapter.kt
index e5449ed..1b131d6 100644
--- a/app/src/main/java/Adapters/PacienteAdapter.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/PacienteAdapter.kt
@@ -1,6 +1,6 @@
-package Adapters
+package com.terratenientes.medicalhealth.adapters
-import Data.Paciente
+import com.terratenientes.medicalhealth.data.Paciente
import android.content.Context
import android.view.LayoutInflater
import android.view.View
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/java/Adapters/RecetaAdapter.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaAdapter.kt
similarity index 91%
rename from app/src/main/java/Adapters/RecetaAdapter.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaAdapter.kt
index 5d8775f..8ed6b64 100644
--- a/app/src/main/java/Adapters/RecetaAdapter.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaAdapter.kt
@@ -1,6 +1,6 @@
-package Adapters
+package com.terratenientes.medicalhealth.adapters
-import Data.Receta
+import com.terratenientes.medicalhealth.data.Receta
import android.content.Context
import android.view.LayoutInflater
import android.view.View
diff --git a/app/src/main/java/Adapters/RecetaDataBaseHelper.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaDataBaseHelper.kt
similarity index 55%
rename from app/src/main/java/Adapters/RecetaDataBaseHelper.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaDataBaseHelper.kt
index 592cb2f..4ce9d26 100644
--- a/app/src/main/java/Adapters/RecetaDataBaseHelper.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaDataBaseHelper.kt
@@ -1,11 +1,13 @@
-package Adapters
+package com.terratenientes.medicalhealth.adapters
-import Data.Receta
+import com.terratenientes.medicalhealth.data.Receta
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
+import android.util.Log
+import com.terratenientes.medicalhealth.data.Paciente
class RecetaDataBaseHelper(context: Context) : SQLiteOpenHelper(context, DATABAENAME, null, DATABASEVERSION){
companion object{
@@ -53,6 +55,29 @@ class RecetaDataBaseHelper(context: Context) : SQLiteOpenHelper(context, DATABAE
val recetas = mutableListOf()
val db = readableDatabase
val cursor = db.rawQuery("SELECT * FROM $TABLE_NAME", null)
+ //val cursor : Cursor =db.query(TABLE_NAME,null,null,null,null,null,null)
+ if(cursor!=null){
+ while (cursor.moveToNext()) {
+ val nombrePaciente = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE_PACIENTE))
+ val edadPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_EDAD_PACIENTE))
+ val pesoPaciente = cursor.getDouble(cursor.getColumnIndex(COLUMN_PESO_PACIENTE))
+ val medicamento = cursor.getString(cursor.getColumnIndex(COLUMN_MEDICAMENTO))
+ val fecha = cursor.getString(cursor.getColumnIndex(COLUMN_FECHA))
+ val dosis = cursor.getString(cursor.getColumnIndex(COLUMN_DOSIS_PACIENTE))
+ val duracion = cursor.getString(cursor.getColumnIndex(DURACION_MEDICAMENTO))
+ val receta = Receta(nombrePaciente, edadPaciente, pesoPaciente, medicamento, fecha, dosis, duracion)
+ recetas.add(receta)
+ }
+ cursor.close()
+ }
+ db.close()
+ return recetas
+ }
+ @SuppressLint("Range")
+ fun obtenerRecetasPaciente(nombrePaciente : String): List{
+ val recetas = mutableListOf()
+ val db = readableDatabase
+ val cursor = db.rawQuery("SELECT * FROM $TABLE_NAME WHERE $COLUMN_NOMBRE_PACIENTE = '$nombrePaciente'", null)
while (cursor.moveToNext()) {
val nombrePaciente = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE_PACIENTE))
val edadPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_EDAD_PACIENTE))
@@ -69,8 +94,32 @@ class RecetaDataBaseHelper(context: Context) : SQLiteOpenHelper(context, DATABAE
}
fun eliminarReceta(receta: Receta) {
+ Log.d("RecetaDataBaseHelper", "Eliminando receta: ${receta.NombrePaciente}, ${receta.fecha}")
val db = writableDatabase
db.delete(TABLE_NAME, "$COLUMN_NOMBRE_PACIENTE = ? AND $COLUMN_FECHA = ?", arrayOf(receta.NombrePaciente, receta.fecha))
db.close()
}
+
+ fun modificarReceta(receta: Receta){
+ val db = writableDatabase
+ val values = ContentValues().apply {
+ put(COLUMN_EDAD_PACIENTE, receta.edadPaciente)
+ put(COLUMN_PESO_PACIENTE, receta.pesoPaciente)
+ put(COLUMN_MEDICAMENTO, receta.nombreMedicamento)
+ put(COLUMN_FECHA, receta.fecha)
+ put(COLUMN_DOSIS_PACIENTE, receta.dosis)
+ put(DURACION_MEDICAMENTO, receta.duracion)
+ }
+ val whereClause = "$COLUMN_NOMBRE_PACIENTE = ? and $COLUMN_FECHA = ?"
+ val whereArgs = arrayOf(receta.NombrePaciente, receta.fecha)
+ db.update(TABLE_NAME, values, whereClause, whereArgs)
+ db.close()
+ }
+
+ fun crearTablaReceta(){
+ val db=writableDatabase
+ val creatTabla="CREATE TABLE $TABLE_NAME ($COLUMN_NOMBRE_PACIENTE VARCHAR(30), $COLUMN_EDAD_PACIENTE INT, $COLUMN_PESO_PACIENTE INT, $COLUMN_FECHA VARCHAR(30), " +
+ "$COLUMN_MEDICAMENTO VARCHAR(30), $DURACION_MEDICAMENTO VARCHAR(20), $COLUMN_DOSIS_PACIENTE VARCHAR(30))"
+ db?.execSQL(creatTabla)
+ }
}
diff --git a/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaViewAdapter.kt b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaViewAdapter.kt
new file mode 100644
index 0000000..a31a22d
--- /dev/null
+++ b/app/src/main/java/com/terratenientes/medicalhealth/adapters/RecetaViewAdapter.kt
@@ -0,0 +1,63 @@
+package com.terratenientes.medicalhealth.adapters
+
+import android.content.Context
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.Button
+import android.widget.ImageView
+import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
+import com.terratenientes.medicalhealth.R
+import com.terratenientes.medicalhealth.data.Receta
+
+class RecetaViewAdapter(private var notes : List, context: Context, val cellClickListener: CellClickListener) :
+ RecyclerView.Adapter() {
+ class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
+ val tituloReceta : TextView = itemView.findViewById(R.id.tv_titulo_receta)
+ val fechaReceta : TextView = itemView.findViewById(R.id.tv_fecha_receta)
+ val nombreReceta : TextView = itemView.findViewById(R.id.tv_nombre_paciente)
+ val btnDescargar : ImageView = itemView.findViewById(R.id.iv_descargar_receta)
+ val btnEliminar: ImageView = itemView.findViewById(R.id.iv_eliminar_receta)
+ val btnModificar : ImageView = itemView.findViewById(R.id.iv_modificar_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)
+ val duracionReceta : TextView= itemView.findViewById(R.id.tv_duracion_receta)
+
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteViewHolder {
+ val view = LayoutInflater.from(parent.context).inflate(R.layout.rc_receta_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.tituloReceta.text = note.nombreMedicamento
+ holder.fechaReceta.text = note.fecha
+ holder.dosisReceta.text=note.dosis
+ holder.duracionReceta.text=note.duracion
+ holder.nombreReceta.text=note.NombrePaciente
+ holder.pesoReceta.text= note.pesoPaciente.toString()
+ holder.edadReceta.text=note.edadPaciente.toString()
+ holder.btnDescargar.setOnClickListener{
+ cellClickListener.onCellClickListener(position)
+ }
+ holder.btnEliminar.setOnClickListener{
+ cellClickListener.onEliminarClickListener(position)
+ }
+ holder.btnModificar.setOnClickListener {
+ cellClickListener.onModifyClickListener(position)
+ }
+ }
+
+ fun refreshData( newNotes : List){
+ this.notes=newNotes
+ notifyDataSetChanged()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/Data/Doctor.kt b/app/src/main/java/com/terratenientes/medicalhealth/data/Doctor.kt
similarity index 73%
rename from app/src/main/java/Data/Doctor.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/data/Doctor.kt
index 9138c25..d23ba62 100644
--- a/app/src/main/java/Data/Doctor.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/data/Doctor.kt
@@ -1,3 +1,3 @@
-package Data
+package com.terratenientes.medicalhealth.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/com/terratenientes/medicalhealth/data/Paciente.kt
similarity index 84%
rename from app/src/main/java/Data/Paciente.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/data/Paciente.kt
index 7db0a88..8bd4a1c 100644
--- a/app/src/main/java/Data/Paciente.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/data/Paciente.kt
@@ -1,4 +1,4 @@
-package Data
+package com.terratenientes.medicalhealth.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/com/terratenientes/medicalhealth/data/Receta.kt b/app/src/main/java/com/terratenientes/medicalhealth/data/Receta.kt
new file mode 100644
index 0000000..b41277f
--- /dev/null
+++ b/app/src/main/java/com/terratenientes/medicalhealth/data/Receta.kt
@@ -0,0 +1,3 @@
+package com.terratenientes.medicalhealth.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/com/terratenientes/medicalhealth/reports/ConsultarPacientesActivity.kt
similarity index 95%
rename from app/src/main/java/Reports/ConsultarPacientesActivity.kt
rename to app/src/main/java/com/terratenientes/medicalhealth/reports/ConsultarPacientesActivity.kt
index d393697..292a395 100644
--- a/app/src/main/java/Reports/ConsultarPacientesActivity.kt
+++ b/app/src/main/java/com/terratenientes/medicalhealth/reports/ConsultarPacientesActivity.kt
@@ -1,4 +1,4 @@
-package Reports
+package com.terratenientes.medicalhealth.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 com.terratenientes.medicalhealth.adapters.DoctorDataBaseHelper
import com.terratenientes.medicalhealth.ModificarActivity
-import Data.Paciente
-import Adapters.PacienteAdapter
+import com.terratenientes.medicalhealth.data.Paciente
+import com.terratenientes.medicalhealth.adapters.PacienteAdapter
import com.terratenientes.medicalhealth.R
import com.terratenientes.medicalhealth.databinding.ActivityConsultarPacientesBinding
import java.io.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/delete.xml b/app/src/main/res/drawable/delete.xml
new file mode 100644
index 0000000..3084d69
--- /dev/null
+++ b/app/src/main/res/drawable/delete.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/download.xml b/app/src/main/res/drawable/download.xml
new file mode 100644
index 0000000..4ba6b80
--- /dev/null
+++ b/app/src/main/res/drawable/download.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/drawable/update.xml b/app/src/main/res/drawable/update.xml
new file mode 100644
index 0000000..6849a5f
--- /dev/null
+++ b/app/src/main/res/drawable/update.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 980949c..01821a2 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"
/>
-
-
-
-
diff --git a/app/src/main/res/layout/activity_consultar_pacientes.xml b/app/src/main/res/layout/activity_consultar_pacientes.xml
index 5a75051..b2f591a 100644
--- a/app/src/main/res/layout/activity_consultar_pacientes.xml
+++ b/app/src/main/res/layout/activity_consultar_pacientes.xml
@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- tools:context="Reports.ConsultarPacientesActivity">
+ tools:context=".reports.ConsultarPacientesActivity">