Funcionalidad Pantalla Agregar

This commit is contained in:
mosterTeco 2024-04-21 00:07:43 -06:00
parent bc005717db
commit 77ba869d72
7 changed files with 123 additions and 20 deletions

View File

@ -1,15 +1,44 @@
package com.terratenientes.medicalhealth
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.ActivityAgregarPacienteBinding
import com.terratenientes.medicalhealth.databinding.ActivityMainBinding
class AgregarActivity : AppCompatActivity() {
private lateinit var binding: ActivityAgregarPacienteBinding
private lateinit var db: DoctorDataBaseHelper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_agregar_paciente)
binding = ActivityAgregarPacienteBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
db = DoctorDataBaseHelper(this@AgregarActivity)
binding.btnConfirmar.setOnClickListener {
agregarPaciente()
}
}
private fun agregarPaciente() {
val nombre = binding.edtxNombre.text.toString()
val apellidoPaterno = binding.edtxApellidoPat.text.toString()
val apellidoMaterno = binding.edtxApellidoMat.text.toString()
val edad = binding.edtxEdad.text.toString().toIntOrNull()
val sexo = binding.edtxSexo.text.toString()
val domicilio = binding.edtxDomicilio.text.toString()
if (nombre.isNotEmpty() && apellidoPaterno.isNotEmpty() && apellidoMaterno.isNotEmpty() && edad != null && sexo.isNotEmpty() && domicilio.isNotEmpty()) {
val paciente = Paciente(0, nombre, apellidoPaterno, apellidoMaterno, edad, sexo, domicilio)
db.agregarPaciente(paciente)
Toast.makeText(this@AgregarActivity, "Paciente registrado correctamente", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@AgregarActivity, "Por favor ingrese todos los campos", Toast.LENGTH_SHORT).show()
}
}
}

View File

@ -19,19 +19,35 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
private const val COLUMN_TELEFONO="Telefono"
private const val COLUMN_CONSULTORIO="Consultorio"
private const val COLUMN_CONTRASENA="Contrasena"
private const val TABLE_PACIENTES = "Pacientes"
private const val COLUMN_ID_PACIENTE = "IdPaciente"
private const val COLUMN_NOMBRE_PACIENTE = "NombrePaciente"
private const val COLUMN_APELLIDO_PATERNO_PACIENTE = "ApellidoPaternoPaciente"
private const val COLUMN_APELLIDO_MATERNO_PACIENTE = "ApellidoMaternoPaciente"
private const val COLUMN_EDAD = "Edad"
private const val COLUMN_SEXO = "Sexo"
private const val COLUMN_DOMICILIO = "Domicilio"
}
@SuppressLint("SuspiciousIndentation")
override fun onCreate(db: SQLiteDatabase?) {
val crearTablaDoctores="CREATE TABLE $TABLE_NAME($COLUMN_CEDULA VARCHAR(30) PRIMARY KEY, $COLUMN_NOMBRE VARCHAR(30)," +
"$COLUMN_APELLIDO VARCHAR(30), $COLUMN_TELEFONO VARCHAR(30), $COLUMN_CONSULTORIO INTEGER, $COLUMN_CONTRASENA VARCHAR(30));"
db?.execSQL(crearTablaDoctores)
val crearTablaPacientes =
"CREATE TABLE $TABLE_PACIENTES($COLUMN_ID_PACIENTE INTEGER PRIMARY KEY AUTOINCREMENT, " +
"$COLUMN_NOMBRE_PACIENTE VARCHAR(30), $COLUMN_APELLIDO_PATERNO_PACIENTE VARCHAR(30), " +
"$COLUMN_APELLIDO_MATERNO_PACIENTE VARCHAR(30), $COLUMN_EDAD INTEGER, $COLUMN_SEXO VARCHAR(10), " +
"$COLUMN_DOMICILIO VARCHAR(100));"
db?.execSQL(crearTablaPacientes)
}
override fun onUpgrade(db: SQLiteDatabase?, p1: Int, p2: Int) {
val dropTableDoctores = "DROP TABLE IF EXISTS $TABLE_NAME"
db?.execSQL(dropTableDoctores)
val dropTablePacientes = "DROP TABLE IF EXISTS $TABLE_PACIENTES"
db?.execSQL(dropTablePacientes)
}
fun agregarDoctores(doctor : Doctor, contrasena: String){
val db=writableDatabase
@ -46,6 +62,19 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
db.insert(TABLE_NAME,null, values)
db.close()
}
fun agregarPaciente(paciente: Paciente) {
val db = writableDatabase
val values = ContentValues().apply {
put(COLUMN_NOMBRE_PACIENTE, paciente.nombre)
put(COLUMN_APELLIDO_PATERNO_PACIENTE, paciente.apellidoPaterno)
put(COLUMN_APELLIDO_MATERNO_PACIENTE, paciente.apellidoMaterno)
put(COLUMN_EDAD, paciente.edad)
put(COLUMN_SEXO, paciente.sexo)
put(COLUMN_DOMICILIO, paciente.domicilio)
}
db.insert(TABLE_PACIENTES, null, values)
db.close()
}
fun createTable(){
val db=writableDatabase
val crearTablaDoctores="CREATE TABLE $TABLE_NAME($COLUMN_CEDULA VARCHAR(30) PRIMARY KEY, $COLUMN_NOMBRE VARCHAR(30)," +
@ -66,5 +95,12 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
return isValid
}
fun eliminarPaciente(paciente: Paciente) {
val db = writableDatabase
val selection = "$COLUMN_ID_PACIENTE = ?"
val selectionArgs = arrayOf(paciente.id.toString())
db.delete(TABLE_PACIENTES, selection, selectionArgs)
db.close()
}
}
}

View File

@ -5,11 +5,18 @@ import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.terratenientes.medicalhealth.databinding.ActivityAgregarPacienteBinding
import com.terratenientes.medicalhealth.databinding.ActivityEliminarPacienteBinding
class EliminarActivity : AppCompatActivity() {
private lateinit var binding: ActivityEliminarPacienteBinding
private lateinit var db: DoctorDataBaseHelper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_eliminar_paciente)
binding = ActivityEliminarPacienteBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
db = DoctorDataBaseHelper(this@EliminarActivity)
}
}

View File

@ -1,6 +1,7 @@
package com.terratenientes.medicalhealth
import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
@ -20,10 +21,17 @@ class MainActivity : AppCompatActivity() {
var res=db.validarDatos(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, AgregarActivity::class.java)
startActivity(intent)
}else{
Toast.makeText(this@MainActivity," NO VALIDADO",Toast.LENGTH_LONG).show()
}
}
binding.btnPrueba.setOnClickListener {
val intent = Intent(this@MainActivity, AgregarActivity::class.java)
startActivity(intent)
}
}
@SuppressLint("SuspiciousIndentation")
private fun cargarDatos(){

View File

@ -10,7 +10,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="5dp"
android:textSize="32dp"
android:textStyle="bold"
android:textColor="@color/tv_titulo"
@ -21,28 +21,31 @@
<ImageView
android:layout_width="200dp"
android:layout_height="150dp"
android:layout_marginTop="25dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/image_area"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="0dp"
android:orientation="horizontal"
tools:ignore="ExtraText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginStart="40dp"
android:text="@string/et_modificar_edad"/>
<EditText
android:id="@+id/edtx_edad"
android:layout_width="51dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="30dp"
android:inputType="number"
android:digits="1234567890"
/>
@ -52,56 +55,63 @@
android:layout_marginStart="0dp"
android:text="@string/et_modificar_sexo" />
<Spinner
<EditText
android:id="@+id/edtx_sexo"
android:layout_width="109dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="50dp" />
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp" />
</LinearLayout>
<EditText
android:id="@+id/edtx_nombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginTop="10dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:hint="@string/ht_nombre"/>
<EditText
android:id="@+id/edtx_apellidoPat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="10dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:hint="@string/ht_apellido_paterno"/>
<EditText
android:id="@+id/edtx_apellidoMat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="10dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:hint="@string/ht_apellido_materno"/>
<EditText
android:id="@+id/edtx_domicilio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="10dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:hint="@string/ht_domicilio"/>
<Button
android:id="@+id/btn_confirmar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="50dp"
android:text="@string/bt_agregar" />
<Button
android:id="@+id/btn_cancelar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bt_cancelar"
android:layout_marginTop="5dp"
android:layout_marginTop="2dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"/>

View File

@ -19,6 +19,7 @@
/>
<ListView
android:id="@+id/lista_pacientes"
android:layout_width="match_parent"
android:layout_height="195dp"
android:layout_marginStart="20dp"
@ -26,6 +27,7 @@
android:layout_marginEnd="5dp" />
<Button
android:id="@+id/btn_eliminar_paciente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"

View File

@ -57,6 +57,17 @@
android:backgroundTint="@color/tv_titulo"
/>
<Button
android:id="@+id/btn_prueba"
android:layout_marginTop="25dp"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Prueba"
android:layout_gravity="center_horizontal"
android:background="@drawable/radius_btn"
android:backgroundTint="@color/tv_titulo"
/>
<TextView
android:layout_marginTop="25dp"
android:id="@+id/tv_registrarme"