<repo_name>HoangNgocDoanh/HealthManagement_app<file_sep>/app/src/main/java/com/cuoiky/smartdoctor/MyDoctorInfoActivity.java
package com.cuoiky.smartdoctor;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MyDoctorInfoActivity extends AppCompatActivity {

    Intent oldIntent;
    TextView fullName,DOB;
    Statement functionStatement;
    FloatingActionButton addbtn;
    Button schedule;

    DBConnector dbConnector = new DBConnector();
    Connection con = dbConnector.getCon();

    @SuppressLint("RestrictedApi")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_doctors_info);

        fullName = findViewById(R.id.fullName_Info);
        DOB = findViewById(R.id.birthDate_Info);
        addbtn = findViewById(R.id.fab);
        schedule = findViewById(R.id.btnappointment);

        oldIntent = getIntent();
// vào từ mypatient
        if (oldIntent.getStringExtra("ID_DOCTOR") != null) {
            getDoctorforSearchActivity(oldIntent.getStringExtra("ID_DOCTOR"));
            addbtn.setVisibility(View.VISIBLE);
            schedule.setVisibility(View.GONE);
        }
        // vào từ search
        else {
            getMyDoctor();
            addbtn.setVisibility(View.GONE);
            schedule.setVisibility(View.VISIBLE);
        }
    }

    public void getMyDoctor() {
        String patient_id = oldIntent.getStringExtra("ID_PATIENT_USER");
        try {
             functionStatement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = functionStatement.executeQuery("select * from res_doctor_GetbyId("+ patient_id +")");
            if (resultSet.first()) {
                fullName.setText(resultSet.getString("fullName") != null ? resultSet.getString("fullName") : "");
                DOB.setText(resultSet.getString("DOB") != null ? resultSet.getString("DOB") : "");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void getDoctorforSearchActivity(String DoctorId) {
        try {
            CallableStatement statement = con.prepareCall("exec res_doctor_GetbyDoctorId ?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            statement.setString(1,DoctorId);
            statement.execute();
            ResultSet resultSet = statement.getResultSet();
            if (resultSet.first()) {
                fullName.setText(resultSet.getString("fullName") != null ? resultSet.getString("fullName") : "");
                DOB.setText(resultSet.getString("DOB") != null ? resultSet.getString("DOB") : "");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void phoneCall(View view) {

    }

    public void Gmail(View view) {

    }

    public void scheduleAppointment(View view) {
        String patient_id = oldIntent.getStringExtra("ID_PATIENT_USER");
        Intent schedule = new Intent(this, ScheduleActivity.class);
        schedule.putExtra("ID_USER",patient_id);
        startActivity(schedule);
    }

    public void addDoctor(View view) {
        try {
            CallableStatement statement = con.prepareCall("exec res_patient_AddDoctor ?,?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            statement.setString(1,oldIntent.getStringExtra("ID_PATIENT_USER"));
            statement.setString(2,oldIntent.getStringExtra("ID_DOCTOR"));
            statement.execute();
            if (!statement.execute()) {
                Toast.makeText(MyDoctorInfoActivity.this,"Your doctor now!",Toast.LENGTH_LONG).show();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
<file_sep>/app/src/main/java/com/cuoiky/smartdoctor/SignUp.java
package com.cuoiky.smartdoctor;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SignUp extends AppCompatActivity {

    TextView Loginhere;
    EditText username,password;
    Button btnsignup;
    RadioButton rddoctor, rdpatient;

    DBConnector dbConnector = new DBConnector();
    Connection con = dbConnector.getCon();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);
        Loginhere = findViewById(R.id.txtLoginhere);
        username = findViewById(R.id.txtUsername);
        password = findViewById(R.id.txtPassword);
        btnsignup = findViewById(R.id.btnSignup);
        rddoctor = findViewById(R.id.rdDoctor);
        rdpatient = findViewById(R.id.rdPatients);
    }

    public void SignUp (View view) {
        try {
            String uname = username.getText().toString().trim();
            String pass = password.getText().toString().trim();
            String isdoctor;
            if (rddoctor.isChecked())
            {
                isdoctor = "1";
            }
            else {
                isdoctor = "0";
            }
            if (!TextUtils.isEmpty(uname) && !TextUtils.isEmpty(pass)) {
                CallableStatement statement = con.prepareCall("exec res_user_sign_up ?,?,?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                statement.setString(1, uname);
                statement.setString(2, pass);
                statement.setString(3,isdoctor);
                statement.execute();

                Toast.makeText(this,"Đăng ký thành công!",Toast.LENGTH_LONG).show();

                Intent mainmenu = new Intent(this, Login.class);
                startActivity(mainmenu);
            }
            else {
                Toast.makeText(this,"Vui lòng nhập thông tin đăng ký!",Toast.LENGTH_LONG).show();
            }
        }
        catch (SQLException e){
            e.printStackTrace();
            Toast.makeText(this,"Đăng ký thất bại!",Toast.LENGTH_LONG).show();
        }
    }
}<file_sep>/app/src/main/java/com/cuoiky/smartdoctor/DisplayPatientInfo.java
package com.cuoiky.smartdoctor;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DisplayPatientInfo extends AppCompatActivity {
    TextView fullName,DOB;
    Statement functionStatement;
    SharedPreferences sharedPreferences;
    FloatingActionButton addbtn;
    FloatingActionButton billbtn;
    Intent oldIntent;
    DBConnector dbConnector = new DBConnector();
    Connection con = dbConnector.getCon();

    @SuppressLint("RestrictedApi")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_patients_info);

        oldIntent = getIntent();

        fullName = findViewById(R.id.fullName_Info_Patients);
        DOB = findViewById(R.id.birthDate_Info_Patients);
        addbtn = findViewById(R.id.fab);
        billbtn =findViewById(R.id.fab3);

        //vao tu my patient
        if (oldIntent.getStringExtra("ID_DOCTOR_USER") != null) {
            addbtn.setVisibility(View.VISIBLE);
            billbtn.setVisibility(View.VISIBLE);

        //vao tu search
        } else {
            addbtn.setVisibility(View.GONE);
            billbtn.setVisibility(View.GONE);
        }
        getpatientforSearchActivity(oldIntent.getStringExtra("ID_PATIENTS"));
    }


    public void getpatientforSearchActivity(String PatientId) {
        try {
            CallableStatement statement = con.prepareCall("exec res_Patients_GetbyPatientsId ?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            statement.setString(1,PatientId);
            statement.execute();
            ResultSet resultSet = statement.getResultSet();
            if (resultSet.first()) {
                fullName.setText(resultSet.getString("fullName") != null ? resultSet.getString("fullName") : "");
                DOB.setText(resultSet.getString("DOB") != null ? resultSet.getString("DOB") : "");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void addmedical(View view) {
        String Id = oldIntent.getStringExtra("ID_PATIENTS");
        Intent addmedical = new Intent(this, AddMedicalActivity.class);
        addmedical.putExtra("ID_PATIENTS",Id);
        startActivity(addmedical);

    }
    public void addbill (View view) {
        String p_id = oldIntent.getStringExtra("ID_PATIENTS");
        try {
            CallableStatement statement = con.prepareCall("exec res_doctor_PayBill ?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            statement.setString(1, p_id);
            statement.execute();
            Toast.makeText(this,"Thanh toán thành công!",Toast.LENGTH_LONG).show();
            Intent mainmenu = new Intent(this, DoctorMenuActivity.class);
            startActivity(mainmenu);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void phoneCall(View view) {

    }

    public void Gmail(View view) {

    }
}
<file_sep>/app/src/main/java/com/cuoiky/smartdoctor/MyPatientsActivity.java
package com.cuoiky.smartdoctor;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class MyPatientsActivity extends AppCompatActivity {
    Intent oldIntent;
    SharedPreferences sharedPreferences;
    ListView listView;
    ArrayAdapter<String> adapter;
    DBConnector dbConnector = new DBConnector();
    Connection con = dbConnector.getCon();
    Statement functionStatement;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_patients);
        oldIntent = getIntent();
        listView = findViewById(R.id.myPatients);
        sharedPreferences = getSharedPreferences("login",MODE_PRIVATE);
        ArrayList<String> ListPatient = new ArrayList<>();
        ArrayList<String> ListPatientId;
        ListPatient = getPatients();
        ListPatientId = getPatientId();
        adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ListPatient);
        listView.setAdapter(adapter);
        final ArrayList<String> finalListPatientsId = ListPatientId;
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent PatientsInfo = new Intent(MyPatientsActivity.this, DisplayPatientInfo.class);
                PatientsInfo.putExtra("ID_PATIENTS", finalListPatientsId.get(position));
                PatientsInfo.putExtra("ID_DOCTOR_USER",oldIntent.getStringExtra("ID_DOCTOR_USER"));
                startActivity(PatientsInfo);
            }
        });
    }

    /// Get Patients
    public ArrayList<String> getPatients() {
        String Doctor_id = "";
        if (oldIntent != null && oldIntent.getStringExtra("ID_USER") != null) {
            Doctor_id = oldIntent.getStringExtra("ID_USER");
        }
        else {
            Doctor_id = sharedPreferences.getString("ID_USER","");
        }
        ArrayList<String> arrayList = new ArrayList<>();
        try {
            functionStatement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = functionStatement.executeQuery("select * from res_doctor_res_patients_GetById("+Doctor_id+")");
            while (resultSet.next()) {
                arrayList.add(resultSet.getString("fullName") != null ? resultSet.getString("fullName") : "");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return arrayList;
    }
    public ArrayList<String> getPatientId() {
        ArrayList<String> arrayList = new ArrayList<>();
        try {
            functionStatement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = functionStatement.executeQuery("select * from res_doctor_res_patients_GetAll()");
            while (resultSet.next()) {
                arrayList.add(resultSet.getString("pid") != null ? resultSet.getString("pid") : "");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return arrayList;
    }
}
