Compare commits
2 Commits
b49828a221
...
cbe7bc5caa
Author | SHA1 | Date |
---|---|---|
sebastiancc27 | cbe7bc5caa | |
sebastiancc27 | 87b519cfd6 |
|
@ -3,7 +3,20 @@
|
|||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State />
|
||||
<State>
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="C:\Users\Hp\.android\avd\Pixel_3a_API_34.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-05-10T04:34:58.235157600Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue