Descargar PDF en Finalizado, pulir recycle view

This commit is contained in:
sebastiancc27 2024-05-10 21:15:45 -06:00
parent 60134f3c66
commit 28c4ea83af
6 changed files with 123 additions and 50 deletions

View File

@ -3,20 +3,7 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State> <State />
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="DVR0219131001092" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-05-10T07:24:34.105307800Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>

View File

@ -76,16 +76,16 @@ class RecetaDataBaseHelper(context: Context) : SQLiteOpenHelper(context, DATABAE
fun obtenerRecetasPaciente(nombrePaciente : String): List<Receta>{ fun obtenerRecetasPaciente(nombrePaciente : String): List<Receta>{
val recetas = mutableListOf<Receta>() val recetas = mutableListOf<Receta>()
val db = readableDatabase val db = readableDatabase
val cursor = db.rawQuery("SELECT $COLUMN_NOMBRE_PACIENTE,$COLUMN_MEDICAMENTO, $COLUMN_FECHA FROM $TABLE_NAME WHERE $COLUMN_NOMBRE_PACIENTE = '$nombrePaciente'", null) val cursor = db.rawQuery("SELECT * FROM $TABLE_NAME WHERE $COLUMN_NOMBRE_PACIENTE = '$nombrePaciente'", null)
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
val nombrePaciente = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE_PACIENTE)) val nombrePaciente = cursor.getString(cursor.getColumnIndex(COLUMN_NOMBRE_PACIENTE))
//val edadPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_EDAD_PACIENTE)) val edadPaciente = cursor.getInt(cursor.getColumnIndex(COLUMN_EDAD_PACIENTE))
//val pesoPaciente = cursor.getDouble(cursor.getColumnIndex(COLUMN_PESO_PACIENTE)) val pesoPaciente = cursor.getDouble(cursor.getColumnIndex(COLUMN_PESO_PACIENTE))
val medicamento = cursor.getString(cursor.getColumnIndex(COLUMN_MEDICAMENTO)) val medicamento = cursor.getString(cursor.getColumnIndex(COLUMN_MEDICAMENTO))
val fecha = cursor.getString(cursor.getColumnIndex(COLUMN_FECHA)) val fecha = cursor.getString(cursor.getColumnIndex(COLUMN_FECHA))
//val dosis = cursor.getString(cursor.getColumnIndex(COLUMN_DOSIS_PACIENTE)) val dosis = cursor.getString(cursor.getColumnIndex(COLUMN_DOSIS_PACIENTE))
//val duracion = cursor.getString(cursor.getColumnIndex(DURACION_MEDICAMENTO)) val duracion = cursor.getString(cursor.getColumnIndex(DURACION_MEDICAMENTO))
val receta = Receta(nombrePaciente, 0, 0.0, medicamento, fecha, "dosis", "duracion") val receta = Receta(nombrePaciente, edadPaciente, pesoPaciente, medicamento, fecha, dosis, duracion)
recetas.add(receta) recetas.add(receta)
} }
cursor.close() cursor.close()

View File

@ -17,7 +17,12 @@ class RecetaViewAdapter(private var notes : List<Receta>, context: Context,val c
class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){ class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
val tituloReceta : TextView = itemView.findViewById(R.id.tv_titulo_receta) val tituloReceta : TextView = itemView.findViewById(R.id.tv_titulo_receta)
val fechaReceta : TextView = itemView.findViewById(R.id.tv_fecha_receta) val fechaReceta : TextView = itemView.findViewById(R.id.tv_fecha_receta)
val nombreReceta : TextView = itemView.findViewById(R.id.tv_nombre_paciente)
val btnDescargar : Button = itemView.findViewById(R.id.btn_descargar_receta) val btnDescargar : Button = itemView.findViewById(R.id.btn_descargar_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)
} }
@ -34,6 +39,11 @@ class RecetaViewAdapter(private var notes : List<Receta>, context: Context,val c
val note = notes[position] val note = notes[position]
holder.tituloReceta.text = note.nombreMedicamento holder.tituloReceta.text = note.nombreMedicamento
holder.fechaReceta.text = note.fecha 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{ holder.btnDescargar.setOnClickListener{
cellClickListener.onCellClickListener(position) cellClickListener.onCellClickListener(position)
} }

View File

@ -50,14 +50,16 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
} }
override fun onCellClickListener(position: Int) { 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 receta = recetas[position]
val nombrePaciente = receta.NombrePaciente val nombrePaciente = recetas[position].NombrePaciente
val nombreMeciamento=receta.nombreMedicamento val nombreMeciamento=recetas[position].nombreMedicamento
val dosisMedicamento = receta.dosis val dosisMedicamento = recetas[position].dosis
val duracionMedicamento = receta.duracion val duracionMedicamento = recetas[position].duracion
val fechaReceta = receta.fecha val fechaReceta = recetas[position].fecha
val pesoPaciente= receta.pesoPaciente val pesoPaciente= recetas[position].pesoPaciente
val edadPaciente = receta.edadPaciente val edadPaciente = recetas[position].edadPaciente
val descripcionReceta ="Fecha de Consulta: ${fechaReceta}\n" + val descripcionReceta ="Fecha de Consulta: ${fechaReceta}\n" +
"Datos Generales del Paciente : \n " + "Datos Generales del Paciente : \n " +
"Peso del Paciente : ${pesoPaciente}\n" + "Peso del Paciente : ${pesoPaciente}\n" +
@ -65,9 +67,11 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
"Medicamento a Recetar: ${nombreMeciamento}\n Dosis del Medicamento : ${dosisMedicamento}\n" + "Medicamento a Recetar: ${nombreMeciamento}\n Dosis del Medicamento : ${dosisMedicamento}\n" +
"Duración del Tratamiento ${duracionMedicamento} \n" "Duración del Tratamiento ${duracionMedicamento} \n"
if(permisosPDF()){ 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() //Toast.makeText(this@PacientePrincipalActivity, "PERMISOS CONCEDIDOS", Toast.LENGTH_SHORT).show()
generarPDF(nombrePaciente, descripcionReceta) generarPDF(nombrePaciente, descripcionReceta, nombreMeciamento)
}else{ }else{
pedirPermisosPDF() pedirPermisosPDF()
} }
@ -86,7 +90,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
),200) ),200)
} }
fun generarPDF(tituloReceta : String, contenidoReceta : String){ fun generarPDF(tituloReceta : String, contenidoReceta : String, medicamento : String){
if (!permisosPDF()) { if (!permisosPDF()) {
pedirPermisosPDF() pedirPermisosPDF()
return return
@ -112,7 +116,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
} }
pdfDoducment.finishPage(paginaReceta) pdfDoducment.finishPage(paginaReceta)
val directory = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS) val directory = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
val file=File(directory,"Receta.pdf") val file=File(directory,"Receta${medicamento}.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()
@ -134,7 +138,7 @@ class PacientePrincipalActivity : AppCompatActivity(), CellClickListener {
if(grantResults.isNotEmpty() && grantResults.all { it == PackageManager.PERMISSION_GRANTED }){ 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") //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{

View File

@ -27,7 +27,7 @@ class RecetaActivity : AppCompatActivity(), OnItemSelectedListener {
db= RecetaDataBaseHelper(this@RecetaActivity) db= RecetaDataBaseHelper(this@RecetaActivity)
dbPaciente = DoctorDataBaseHelper(this@RecetaActivity) dbPaciente = DoctorDataBaseHelper(this@RecetaActivity)
setContentView(view) setContentView(view)
//db.crearTablaReceta() // db.crearTablaReceta()
cargarSpinnerPacientes() cargarSpinnerPacientes()
binding.spNombrePaciente.onItemSelectedListener=this binding.spNombrePaciente.onItemSelectedListener=this
binding.btnAgregarReceta.setOnClickListener { binding.btnAgregarReceta.setOnClickListener {

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="110dp"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
@ -17,39 +17,51 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="13dp" android:orientation="vertical">
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/tv_nombre_paciente"
android:layout_width="117dp"
android:layout_height="15dp"
android:layout_marginStart="14dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="256dp"
android:layout_marginBottom="75dp"
android:hint="Nombre Paciente"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/tv_titulo_receta" android:id="@+id/tv_titulo_receta"
android:layout_width="wrap_content" android:layout_width="117dp"
android:layout_height="wrap_content" android:layout_height="15dp"
android:layout_marginStart="24dp" android:layout_marginStart="14dp"
android:layout_marginTop="8dp" android:layout_marginTop="50dp"
android:layout_marginEnd="231dp" android:layout_marginEnd="256dp"
android:layout_marginBottom="42dp" android:layout_marginBottom="45dp"
android:hint="Titulo de la Receta" android:hint="Titulo de la Receta"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintVertical_bias="0.571" />
<TextView <TextView
android:id="@+id/tv_fecha_receta" android:id="@+id/tv_fecha_receta"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="32dp" android:layout_marginStart="14dp"
android:layout_marginTop="57dp" android:layout_marginTop="83dp"
android:layout_marginEnd="221dp" android:layout_marginEnd="255dp"
android:layout_marginBottom="8dp"
android:hint="Fecha de la Receta" android:hint="Fecha de la Receta"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintVertical_bias="1.0" />
<Button <Button
android:id="@+id/btn_descargar_receta" android:id="@+id/btn_descargar_receta"
@ -63,8 +75,68 @@
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.487" />
<TextView
android:id="@+id/tv_peso_paciente"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="141dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="196dp"
android:layout_marginBottom="71dp"
android:hint="Peso"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_duracion_receta"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginStart="199dp"
android:layout_marginTop="83dp"
android:layout_marginEnd="128dp"
android:layout_marginBottom="8dp"
android:hint="Duración"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_edad_paciente"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="141dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="196dp"
android:layout_marginBottom="41dp"
android:hint="Edad"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_dosis_medicamento"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="141dp"
android:layout_marginTop="83dp"
android:layout_marginEnd="196dp"
android:layout_marginBottom="8dp"
android:hint="Dosis"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>