Angel #8

Merged
angel.nunez merged 9 commits from Angel into master 2024-05-13 03:12:28 +00:00
2 changed files with 26 additions and 7 deletions
Showing only changes of commit cbe7bc5caa - Show all commits

View File

@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper
import Data.Doctor
import Data.Paciente
import android.database.Cursor
import android.widget.Toast
class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABASE_NAME,null,
DATABASE_VERSION
@ -85,6 +86,7 @@ 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()
}
@ -118,7 +120,7 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
fun validarDatos(usuario :String , contrasena : String): Boolean{
val db = readableDatabase
val validarQuery = "SELECT $COLUMN_CEDULA,$COLUMN_CONTRASENA FROM $TABLE_NAME, $TABLE_PACIENTES WHERE $COLUMN_CEDULA = '$usuario' 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()

View File

@ -6,6 +6,9 @@ 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
@ -34,6 +37,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
idPaciente= intent.getStringExtra("IDPaciente")!!
db= RecetaDataBaseHelper(this)
recetas=db.obtenerRecetasPaciente(idPaciente)
recycleAdapter = RecetaViewAdapter(db.obtenerRecetasPaciente(idPaciente), this, this@PacientePrincipalActivity)
binding.rvRecetasPaciente.layoutManager=LinearLayoutManager(this)
@ -54,19 +58,24 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
val fechaReceta = receta.fecha
val pesoPaciente= receta.pesoPaciente
val edadPaciente = receta.edadPaciente
val descripcionReceta ="Ejemplo de descripcion"
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@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
generarPDF(nombrePaciente, descripcionReceta)
generarPDF(nombrePaciente, descripcionReceta)
}else{
pedirPermisosPDF()
}
}
// función que valida si los permisos ya estan garantizados por parte del usuario
fun permisosPDF() : Boolean{
val permission1= ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.WRITE_EXTERNAL_STORAGE)
val permission2= ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.READ_EXTERNAL_STORAGE)
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
}
@ -76,7 +85,12 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
Manifest.permission.READ_EXTERNAL_STORAGE
),200)
}
fun generarPDF(tituloReceta : String, contenidoReceta : String){
if (!permisosPDF()) {
pedirPermisosPDF()
return
}
val pdfDoducment = PdfDocument()
val tituloPDF = TextPaint()
val contenido = TextPaint()
@ -97,7 +111,8 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
y=y+15
}
pdfDoducment.finishPage(paginaReceta)
val file=File(Environment.getExternalStorageDirectory(),"Receta.pdf")
val directory = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
val file=File(directory,"Receta.pdf")
try {
pdfDoducment.writeTo(FileOutputStream(file))
Toast.makeText(this,"PDF CREADO CORRECTAMENTE",Toast.LENGTH_LONG).show()
@ -108,6 +123,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
pdfDoducment.close()
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
@ -115,9 +131,10 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if(requestCode==200){
if(grantResults.isNotEmpty()){
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{