Angel #8
|
@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper
|
||||||
import Data.Doctor
|
import Data.Doctor
|
||||||
import Data.Paciente
|
import Data.Paciente
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABASE_NAME,null,
|
class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABASE_NAME,null,
|
||||||
DATABASE_VERSION
|
DATABASE_VERSION
|
||||||
|
@ -85,6 +86,7 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
|
||||||
put(COLUMN_DOMICILIO, paciente.domicilio)
|
put(COLUMN_DOMICILIO, paciente.domicilio)
|
||||||
}
|
}
|
||||||
db.insert(TABLE_PACIENTES, null, values)
|
db.insert(TABLE_PACIENTES, null, values)
|
||||||
|
print("ID DEL PACIENTE AGREGADO: "+COLUMN_ID_PACIENTE)
|
||||||
db.close()
|
db.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
|
||||||
|
|
||||||
fun validarDatos(usuario :String , contrasena : String): Boolean{
|
fun validarDatos(usuario :String , contrasena : String): Boolean{
|
||||||
val db = readableDatabase
|
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 cursor = db.rawQuery(validarQuery, null)
|
||||||
val isValid = cursor.count > 0
|
val isValid = cursor.count > 0
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
|
@ -6,6 +6,9 @@ import Adapters.RecetaViewAdapter
|
||||||
import Data.Receta
|
import Data.Receta
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Paint
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.pdf.PdfDocument
|
import android.graphics.pdf.PdfDocument
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -34,6 +37,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
idPaciente= intent.getStringExtra("IDPaciente")!!
|
idPaciente= intent.getStringExtra("IDPaciente")!!
|
||||||
db= RecetaDataBaseHelper(this)
|
db= RecetaDataBaseHelper(this)
|
||||||
recetas=db.obtenerRecetasPaciente(idPaciente)
|
recetas=db.obtenerRecetasPaciente(idPaciente)
|
||||||
|
|
||||||
recycleAdapter = RecetaViewAdapter(db.obtenerRecetasPaciente(idPaciente), this, this@PacientePrincipalActivity)
|
recycleAdapter = RecetaViewAdapter(db.obtenerRecetasPaciente(idPaciente), this, this@PacientePrincipalActivity)
|
||||||
|
|
||||||
binding.rvRecetasPaciente.layoutManager=LinearLayoutManager(this)
|
binding.rvRecetasPaciente.layoutManager=LinearLayoutManager(this)
|
||||||
|
@ -54,19 +58,24 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
val fechaReceta = receta.fecha
|
val fechaReceta = receta.fecha
|
||||||
val pesoPaciente= receta.pesoPaciente
|
val pesoPaciente= receta.pesoPaciente
|
||||||
val edadPaciente = receta.edadPaciente
|
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()){
|
if(permisosPDF()){
|
||||||
//Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
|
//Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
|
||||||
generarPDF(nombrePaciente, descripcionReceta)
|
generarPDF(nombrePaciente, descripcionReceta)
|
||||||
}else{
|
}else{
|
||||||
pedirPermisosPDF()
|
pedirPermisosPDF()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// función que valida si los permisos ya estan garantizados por parte del usuario
|
// función que valida si los permisos ya estan garantizados por parte del usuario
|
||||||
fun permisosPDF() : Boolean{
|
fun permisosPDF() : Boolean{
|
||||||
val permission1= ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
val permission1= ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
val permission2= ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.READ_EXTERNAL_STORAGE)
|
val permission2= ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
|
|
||||||
return permission1 == PackageManager.PERMISSION_GRANTED && permission2 == PackageManager.PERMISSION_GRANTED
|
return permission1 == PackageManager.PERMISSION_GRANTED && permission2 == PackageManager.PERMISSION_GRANTED
|
||||||
}
|
}
|
||||||
|
@ -76,7 +85,12 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
),200)
|
),200)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generarPDF(tituloReceta : String, contenidoReceta : String){
|
fun generarPDF(tituloReceta : String, contenidoReceta : String){
|
||||||
|
if (!permisosPDF()) {
|
||||||
|
pedirPermisosPDF()
|
||||||
|
return
|
||||||
|
}
|
||||||
val pdfDoducment = PdfDocument()
|
val pdfDoducment = PdfDocument()
|
||||||
val tituloPDF = TextPaint()
|
val tituloPDF = TextPaint()
|
||||||
val contenido = TextPaint()
|
val contenido = TextPaint()
|
||||||
|
@ -97,7 +111,8 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
y=y+15
|
y=y+15
|
||||||
}
|
}
|
||||||
pdfDoducment.finishPage(paginaReceta)
|
pdfDoducment.finishPage(paginaReceta)
|
||||||
val file=File(Environment.getExternalStorageDirectory(),"Receta.pdf")
|
val directory = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
|
||||||
|
val file=File(directory,"Receta.pdf")
|
||||||
try {
|
try {
|
||||||
pdfDoducment.writeTo(FileOutputStream(file))
|
pdfDoducment.writeTo(FileOutputStream(file))
|
||||||
Toast.makeText(this,"PDF CREADO CORRECTAMENTE",Toast.LENGTH_LONG).show()
|
Toast.makeText(this,"PDF CREADO CORRECTAMENTE",Toast.LENGTH_LONG).show()
|
||||||
|
@ -108,6 +123,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
pdfDoducment.close()
|
pdfDoducment.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
override fun onRequestPermissionsResult(
|
||||||
requestCode: Int,
|
requestCode: Int,
|
||||||
permissions: Array<out String>,
|
permissions: Array<out String>,
|
||||||
|
@ -115,9 +131,10 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
|
||||||
) {
|
) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
if(requestCode==200){
|
if(requestCode==200){
|
||||||
if(grantResults.isNotEmpty()){
|
if(grantResults.isNotEmpty() && grantResults.all { it == PackageManager.PERMISSION_GRANTED }){
|
||||||
val writeStorage = grantResults[0]==PackageManager.PERMISSION_GRANTED
|
val writeStorage = grantResults[0]==PackageManager.PERMISSION_GRANTED
|
||||||
val readStorage = grantResults[1]==PackageManager.PERMISSION_GRANTED
|
val readStorage = grantResults[1]==PackageManager.PERMISSION_GRANTED
|
||||||
|
generarPDF("Título", "Contenido")
|
||||||
if(writeStorage && readStorage){
|
if(writeStorage && readStorage){
|
||||||
Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
|
||||||
}else{
|
}else{
|
||||||
|
|
Loading…
Reference in New Issue