Funcionalidad Pantalla Agregar
This commit is contained in:
parent
bc005717db
commit
77ba869d72
|
@ -1,15 +1,44 @@
|
||||||
package com.terratenientes.medicalhealth
|
package com.terratenientes.medicalhealth
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import com.terratenientes.medicalhealth.databinding.ActivityAgregarPacienteBinding
|
||||||
|
import com.terratenientes.medicalhealth.databinding.ActivityMainBinding
|
||||||
|
|
||||||
class AgregarActivity : AppCompatActivity() {
|
class AgregarActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityAgregarPacienteBinding
|
||||||
|
private lateinit var db: DoctorDataBaseHelper
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
binding = ActivityAgregarPacienteBinding.inflate(layoutInflater)
|
||||||
setContentView(R.layout.activity_agregar_paciente)
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,19 +19,35 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
|
||||||
private const val COLUMN_TELEFONO="Telefono"
|
private const val COLUMN_TELEFONO="Telefono"
|
||||||
private const val COLUMN_CONSULTORIO="Consultorio"
|
private const val COLUMN_CONSULTORIO="Consultorio"
|
||||||
private const val COLUMN_CONTRASENA="Contrasena"
|
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")
|
@SuppressLint("SuspiciousIndentation")
|
||||||
override fun onCreate(db: SQLiteDatabase?) {
|
override fun onCreate(db: SQLiteDatabase?) {
|
||||||
val crearTablaDoctores="CREATE TABLE $TABLE_NAME($COLUMN_CEDULA VARCHAR(30) PRIMARY KEY, $COLUMN_NOMBRE VARCHAR(30)," +
|
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));"
|
"$COLUMN_APELLIDO VARCHAR(30), $COLUMN_TELEFONO VARCHAR(30), $COLUMN_CONSULTORIO INTEGER, $COLUMN_CONTRASENA VARCHAR(30));"
|
||||||
db?.execSQL(crearTablaDoctores)
|
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) {
|
override fun onUpgrade(db: SQLiteDatabase?, p1: Int, p2: Int) {
|
||||||
val dropTableDoctores = "DROP TABLE IF EXISTS $TABLE_NAME"
|
val dropTableDoctores = "DROP TABLE IF EXISTS $TABLE_NAME"
|
||||||
db?.execSQL(dropTableDoctores)
|
db?.execSQL(dropTableDoctores)
|
||||||
|
|
||||||
|
val dropTablePacientes = "DROP TABLE IF EXISTS $TABLE_PACIENTES"
|
||||||
|
db?.execSQL(dropTablePacientes)
|
||||||
}
|
}
|
||||||
fun agregarDoctores(doctor : Doctor, contrasena: String){
|
fun agregarDoctores(doctor : Doctor, contrasena: String){
|
||||||
val db=writableDatabase
|
val db=writableDatabase
|
||||||
|
@ -46,6 +62,19 @@ class DoctorDataBaseHelper (context: Context) : SQLiteOpenHelper(context, DATABA
|
||||||
db.insert(TABLE_NAME,null, values)
|
db.insert(TABLE_NAME,null, values)
|
||||||
db.close()
|
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(){
|
fun createTable(){
|
||||||
val db=writableDatabase
|
val db=writableDatabase
|
||||||
val crearTablaDoctores="CREATE TABLE $TABLE_NAME($COLUMN_CEDULA VARCHAR(30) PRIMARY KEY, $COLUMN_NOMBRE VARCHAR(30)," +
|
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
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,11 +5,18 @@ import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import com.terratenientes.medicalhealth.databinding.ActivityAgregarPacienteBinding
|
||||||
|
import com.terratenientes.medicalhealth.databinding.ActivityEliminarPacienteBinding
|
||||||
|
|
||||||
class EliminarActivity : AppCompatActivity() {
|
class EliminarActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityEliminarPacienteBinding
|
||||||
|
private lateinit var db: DoctorDataBaseHelper
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
binding = ActivityEliminarPacienteBinding.inflate(layoutInflater)
|
||||||
setContentView(R.layout.activity_eliminar_paciente)
|
val view = binding.root
|
||||||
|
setContentView(view)
|
||||||
|
db = DoctorDataBaseHelper(this@EliminarActivity)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.terratenientes.medicalhealth
|
package com.terratenientes.medicalhealth
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -20,10 +21,17 @@ class MainActivity : AppCompatActivity() {
|
||||||
var res=db.validarDatos(binding.tvUsuario.text.toString(),binding.tvContrasena.text.toString())
|
var res=db.validarDatos(binding.tvUsuario.text.toString(),binding.tvContrasena.text.toString())
|
||||||
if(res==true){
|
if(res==true){
|
||||||
Toast.makeText(this@MainActivity,"VALIDADO",Toast.LENGTH_LONG).show()
|
Toast.makeText(this@MainActivity,"VALIDADO",Toast.LENGTH_LONG).show()
|
||||||
|
val intent = Intent(this@MainActivity, AgregarActivity::class.java)
|
||||||
|
startActivity(intent)
|
||||||
}else{
|
}else{
|
||||||
Toast.makeText(this@MainActivity," NO VALIDADO",Toast.LENGTH_LONG).show()
|
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")
|
@SuppressLint("SuspiciousIndentation")
|
||||||
private fun cargarDatos(){
|
private fun cargarDatos(){
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="5dp"
|
||||||
android:textSize="32dp"
|
android:textSize="32dp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/tv_titulo"
|
android:textColor="@color/tv_titulo"
|
||||||
|
@ -21,28 +21,31 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="150dp"
|
android:layout_height="150dp"
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:src="@drawable/image_area"/>
|
android:src="@drawable/image_area"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="0dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
tools:ignore="ExtraText">
|
tools:ignore="ExtraText">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="65dp"
|
android:layout_marginStart="40dp"
|
||||||
android:text="@string/et_modificar_edad"/>
|
android:text="@string/et_modificar_edad"/>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/edtx_edad"
|
||||||
android:layout_width="51dp"
|
android:layout_width="51dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="20dp"
|
||||||
android:layout_marginEnd="30dp"
|
android:layout_marginEnd="30dp"
|
||||||
|
android:inputType="number"
|
||||||
|
android:digits="1234567890"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,56 +55,63 @@
|
||||||
android:layout_marginStart="0dp"
|
android:layout_marginStart="0dp"
|
||||||
android:text="@string/et_modificar_sexo" />
|
android:text="@string/et_modificar_sexo" />
|
||||||
|
|
||||||
<Spinner
|
<EditText
|
||||||
|
android:id="@+id/edtx_sexo"
|
||||||
android:layout_width="109dp"
|
android:layout_width="109dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="15dp"
|
||||||
android:layout_marginEnd="50dp" />
|
android:layout_marginEnd="10dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/edtx_nombre"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="40dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginStart="40dp"
|
android:layout_marginStart="40dp"
|
||||||
android:layout_marginEnd="40dp"
|
android:layout_marginEnd="40dp"
|
||||||
android:hint="@string/ht_nombre"/>
|
android:hint="@string/ht_nombre"/>
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/edtx_apellidoPat"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginStart="40dp"
|
android:layout_marginStart="40dp"
|
||||||
android:layout_marginEnd="40dp"
|
android:layout_marginEnd="40dp"
|
||||||
android:hint="@string/ht_apellido_paterno"/>
|
android:hint="@string/ht_apellido_paterno"/>
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/edtx_apellidoMat"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginStart="40dp"
|
android:layout_marginStart="40dp"
|
||||||
android:layout_marginEnd="40dp"
|
android:layout_marginEnd="40dp"
|
||||||
android:hint="@string/ht_apellido_materno"/>
|
android:hint="@string/ht_apellido_materno"/>
|
||||||
<EditText
|
<EditText
|
||||||
|
android:id="@+id/edtx_domicilio"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginStart="40dp"
|
android:layout_marginStart="40dp"
|
||||||
android:layout_marginEnd="40dp"
|
android:layout_marginEnd="40dp"
|
||||||
android:hint="@string/ht_domicilio"/>
|
android:hint="@string/ht_domicilio"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/btn_confirmar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="50dp"
|
android:layout_marginStart="50dp"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_marginEnd="50dp"
|
android:layout_marginEnd="50dp"
|
||||||
android:text="@string/bt_agregar" />
|
android:text="@string/bt_agregar" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/btn_cancelar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/bt_cancelar"
|
android:text="@string/bt_cancelar"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="2dp"
|
||||||
android:layout_marginStart="50dp"
|
android:layout_marginStart="50dp"
|
||||||
android:layout_marginEnd="50dp"/>
|
android:layout_marginEnd="50dp"/>
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
android:id="@+id/lista_pacientes"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="195dp"
|
android:layout_height="195dp"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="20dp"
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
android:layout_marginEnd="5dp" />
|
android:layout_marginEnd="5dp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/btn_eliminar_paciente"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="50dp"
|
android:layout_marginStart="50dp"
|
||||||
|
|
|
@ -57,6 +57,17 @@
|
||||||
android:backgroundTint="@color/tv_titulo"
|
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
|
<TextView
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="25dp"
|
||||||
android:id="@+id/tv_registrarme"
|
android:id="@+id/tv_registrarme"
|
||||||
|
|
Loading…
Reference in New Issue