diff --git a/.idea/misc.xml b/.idea/misc.xml index 8978d23..f03e5ec 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -6,4 +7,11 @@ + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ecd309c..00c4ba4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,5 +47,5 @@ dependencies { implementation("com.google.firebase:firebase-analytics") implementation ("com.google.firebase:firebase-firestore:24.11.1") implementation("com.google.firebase:firebase-auth") - + implementation ("com.google.android.material:material:1.4.0") } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1c1a538..4e564a8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,36 +8,83 @@ android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" - android:icon="@mipmap/ic_launcher" android:label="@string/app_name" - android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplication" tools:targetApi="31"> + android:name=".DoctorProfile" + android:exported="false" /> + + + + + + + + + + + + + - + + + - - + android:exported="true" /> + + + - - - \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/AddDoctor.java b/app/src/main/java/com/example/myapplication/AddDoctor.java new file mode 100644 index 0000000..bc006f0 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/AddDoctor.java @@ -0,0 +1,83 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.Objects; + +public class AddDoctor extends AppCompatActivity { + private EditText etDoctorName, etDoctorEmail, etDoctorPhone, etDoctorQualification, + etDoctorExperience, etDoctorCategory, etDoctorPassword, etDoctorConfirmPassword,doctorFeeEditText; + private FirebaseFirestore db; + private FirebaseAuth auth; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_doctor); + + db = FirebaseFirestore.getInstance(); + auth = FirebaseAuth.getInstance(); + + etDoctorName = findViewById(R.id.et_doctor_name); + etDoctorEmail = findViewById(R.id.et_doctor_email); + etDoctorPhone = findViewById(R.id.et_doctor_phone); + etDoctorQualification = findViewById(R.id.et_doctor_qualification); + etDoctorExperience = findViewById(R.id.et_doctor_experience); + etDoctorCategory = findViewById(R.id.et_doctor_category); + etDoctorPassword = findViewById(R.id.et_doctor_password); + etDoctorConfirmPassword = findViewById(R.id.et_doctor_confirm_password); + doctorFeeEditText = findViewById(R.id.doctorFeeEditText); + + Button btnAddDoctor = findViewById(R.id.btn_add_doctor); + + btnAddDoctor.setOnClickListener(v -> { + String Name = etDoctorName.getText().toString().trim(); + String Email = etDoctorEmail.getText().toString().trim(); + String Phone = etDoctorPhone.getText().toString().trim(); + String Qualification = etDoctorQualification.getText().toString().trim(); + String Experience = etDoctorExperience.getText().toString().trim(); + String Category = etDoctorCategory.getText().toString().trim(); + String Password = etDoctorPassword.getText().toString().trim(); + String ConfirmPassword = etDoctorConfirmPassword.getText().toString().trim(); + String fee = doctorFeeEditText.getText().toString().trim(); + if (Name.isEmpty() || Email.isEmpty() || Phone.isEmpty() || Qualification.isEmpty() || + Experience.isEmpty() || Category.isEmpty() || Password.isEmpty() || !Password.equals(ConfirmPassword) || Password.length() < 6) { + Toast.makeText(AddDoctor.this, "Please ensure all fields are filled correctly and passwords match.", Toast.LENGTH_SHORT).show(); + return; + } + + auth.createUserWithEmailAndPassword(Email, Password) + .addOnCompleteListener(task -> { + if (task.isSuccessful()) { + Doctor doctor = new Doctor(Name, Email, Phone, Qualification, Experience, Category,Password,ConfirmPassword,fee); + addDoctorToFirestore(doctor); + } else { + Toast.makeText(AddDoctor.this, "Authentication failed: " + Objects.requireNonNull(task.getException()).getMessage(), Toast.LENGTH_SHORT).show(); + } + }); + }); + } + + private void addDoctorToFirestore(Doctor doctor) { + db.collection("doctors").add(doctor) + .addOnSuccessListener(documentReference -> { + Toast.makeText(AddDoctor.this, "Doctor added successfully", Toast.LENGTH_SHORT).show(); + finish(); // Optional: Close the activity on success + }) + .addOnFailureListener(e -> { + Log.e("AddDoctor", "Error adding doctor to Firestore", e); + Toast.makeText(AddDoctor.this, "Error adding doctor to Firestore: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + }); + } +} diff --git a/app/src/main/java/com/example/myapplication/AdminProfile.java b/app/src/main/java/com/example/myapplication/AdminProfile.java new file mode 100644 index 0000000..4d25032 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/AdminProfile.java @@ -0,0 +1,60 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; + +import java.util.ResourceBundle; + +public class AdminProfile extends AppCompatActivity { + + private TextView txtAdminName; + private Button btnGenerateInvoice, btnViewReports, btnSettings; + + private String adminEmail; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_admin_profile); + + // Initialize views + txtAdminName = findViewById(R.id.txtAdminName); + + btnGenerateInvoice = findViewById(R.id.btnGenerateInvoice); + btnViewReports = findViewById(R.id.btnViewReports); + btnSettings = findViewById(R.id.btnSettings); + + // Get data from intent + Bundle extras = getIntent().getExtras(); + if (extras != null) { + txtAdminName.setText("Name: " + extras.getString("name", "N/A")); + adminEmail = extras.getString("email"); + } + + // Set up button listeners + btnGenerateInvoice.setOnClickListener(v -> openGenerateInvoiceActivity()); + btnViewReports.setOnClickListener(v -> openViewReportsActivity()); + btnSettings.setOnClickListener(v -> openAddDoctor()); + } + + private void openGenerateInvoiceActivity() { + Intent intent = new Intent(AdminProfile.this, GenerateInvoice.class); + startActivity(intent); + finish(); + } + + + private void openViewReportsActivity() + { + + } + + private void openAddDoctor() { + Intent intent = new Intent(AdminProfile.this, AddDoctor.class); + startActivity(intent); + finish(); + } +} diff --git a/app/src/main/java/com/example/myapplication/AppointmentDetailActivity.java b/app/src/main/java/com/example/myapplication/AppointmentDetailActivity.java new file mode 100644 index 0000000..5cfde37 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/AppointmentDetailActivity.java @@ -0,0 +1,58 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; + +public class AppointmentDetailActivity extends AppCompatActivity { + + private TextView txtDate, txtDoctor, txtDescription; + private EditText feedbackInput; + private Button btnSubmitFeedback; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_appointment_detail); + + // Initialize views + txtDate = findViewById(R.id.txtDate); + txtDoctor = findViewById(R.id.txtDoctor); + txtDescription = findViewById(R.id.txtDescription); + feedbackInput = findViewById(R.id.feedbackInput); + btnSubmitFeedback = findViewById(R.id.btnSubmitFeedback); + + // Get data from intent + Bundle extras = getIntent().getExtras(); + if (extras != null) { + String date = extras.getString("date", "No date provided"); + String doctor = extras.getString("doctor", "No doctor specified"); + String description = extras.getString("description", "No description provided"); + + // Set data to views + txtDate.setText("Date: " + date); + txtDoctor.setText("Doctor: " + doctor); + txtDescription.setText("Description: " + description); + } + + // Handle feedback submission + btnSubmitFeedback.setOnClickListener(v -> submitFeedback()); + } + + private void submitFeedback() { + String feedback = feedbackInput.getText().toString(); + if (!feedback.isEmpty()) { + // Handle the feedback submission logic here + // For example, sending feedback to a server or database + Toast.makeText(this, "Feedback submitted. Thank you!", Toast.LENGTH_LONG).show(); + + // Clear the input field after submission + feedbackInput.setText(""); + } else { + Toast.makeText(this, "Please enter some feedback before submitting.", Toast.LENGTH_LONG).show(); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/ApproveAppointmentActivity.java b/app/src/main/java/com/example/myapplication/ApproveAppointmentActivity.java new file mode 100644 index 0000000..baa6d25 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ApproveAppointmentActivity.java @@ -0,0 +1,149 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.QueryDocumentSnapshot; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ApproveAppointmentActivity extends AppCompatActivity { + + private RecyclerView recyclerView; + private AppointmentAdapter adapter; + private List> appointments = new ArrayList<>(); + private FirebaseFirestore db = FirebaseFirestore.getInstance(); + private FirebaseAuth mAuth = FirebaseAuth.getInstance(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.approve_appointment); + + recyclerView = findViewById(R.id.recyclerViewAppointments); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new AppointmentAdapter(appointments); + recyclerView.setAdapter(adapter); + Button okButton = findViewById(R.id.buttonOk); + okButton.setOnClickListener(v -> { + finish(); + }); + + fetchAppointments(); + } + + private void fetchAppointments() { + FirebaseUser currentUser = mAuth.getCurrentUser(); + if (currentUser != null) { + String doctorEmail = currentUser.getEmail(); + db.collection("pendingAppointments") + .whereEqualTo("doctorEmail", doctorEmail) + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful()) { + appointments.clear(); + for (QueryDocumentSnapshot document : task.getResult()) { + Map appointment = new HashMap<>(document.getData()); + appointment.put("id", document.getId()); + appointments.add(appointment); + } + adapter.notifyDataSetChanged(); + } else { + Log.w("FetchAppointments", "Error getting documents.", task.getException()); + } + }); + } else { + Log.w("FetchAppointments", "No user logged in."); + } + } + + + private class AppointmentAdapter extends RecyclerView.Adapter { + + private List> appointments; + + AppointmentAdapter(List> appointments) { + this.appointments = appointments; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.appointment_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + Map appointment = appointments.get(position); + holder.textViewPatientName.setText((String) appointment.get("patientName")); + holder.textViewPatientEmail.setText((String) appointment.get("userEmail")); + holder.textViewAppointmentDate.setText((String) appointment.get("date")); + holder.textViewAppointmentTime.setText((String) appointment.get("time")); + holder.buttonAccept.setOnClickListener(v -> { + moveAppointment(appointment, "ApprovedAppointments"); + }); + holder.buttonReject.setOnClickListener(v -> { + moveAppointment(appointment, "TrashAppointments"); + }); + } + + @Override + public int getItemCount() { + return appointments.size(); + } + + private void moveAppointment(Map appointment, String collectionName) { + FirebaseUser user = mAuth.getCurrentUser(); + if (user != null) { + String userId = user.getUid(); + appointment.put("userId", userId); + db.collection(collectionName) + .add(appointment) + .addOnSuccessListener(documentReference -> { + String appointmentId = (String) appointment.get("id"); + appointments.remove(appointment); + notifyItemRemoved(appointments.indexOf(appointment)); + db.collection("pendingAppointments").document(appointmentId) + .delete() + .addOnSuccessListener(aVoid -> Log.d("DeleteAppointment", "DocumentSnapshot successfully deleted!")) + .addOnFailureListener(e -> Log.w("DeleteAppointment", "Error deleting document", e)); + }) + .addOnFailureListener(e -> Log.w("MoveAppointment", "Error adding document", e)); + } + } + + class ViewHolder extends RecyclerView.ViewHolder { + TextView textViewPatientName, textViewPatientEmail, textViewAppointmentDate, textViewAppointmentTime; + Button buttonAccept, buttonReject; + + ViewHolder(View itemView) { + super(itemView); + textViewPatientName = itemView.findViewById(R.id.textViewPatientName); + textViewPatientEmail = itemView.findViewById(R.id.textViewPatientEmail); + textViewAppointmentDate = itemView.findViewById(R.id.textViewAppointmentDate); + textViewAppointmentTime = itemView.findViewById(R.id.textViewAppointmentTime); + buttonAccept = itemView.findViewById(R.id.buttonAccept); + buttonReject = itemView.findViewById(R.id.buttonReject); + } + } + } + +} diff --git a/app/src/main/java/com/example/myapplication/CancelAppointmentsActivity.java b/app/src/main/java/com/example/myapplication/CancelAppointmentsActivity.java new file mode 100644 index 0000000..8b7aedb --- /dev/null +++ b/app/src/main/java/com/example/myapplication/CancelAppointmentsActivity.java @@ -0,0 +1,154 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.QueryDocumentSnapshot; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CancelAppointmentsActivity extends AppCompatActivity { + + private RecyclerView recyclerView; + private AppointmentAdapter adapter; + private FirebaseFirestore db = FirebaseFirestore.getInstance(); + FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser(); + private String currentUserId = currentUser.getUid(); // or currentUser.getEmail() if you are using emails +private String email; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_cancel_appointments); // Ensure this layout contains the RecyclerView + + recyclerView = findViewById(R.id.textViewAppointmentDetails); // Correct ID for RecyclerView + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new AppointmentAdapter(new ArrayList<>()); + recyclerView.setAdapter(adapter); + + // Get email passed from PatientProfile + Intent intent = getIntent(); + if (intent != null && intent.hasExtra("email")) { + email = intent.getStringExtra("email"); // Store the email + } + if (currentUser != null) { + fetchApprovedAppointments(currentUserId); + } else { + Toast.makeText(this, "No user logged in", Toast.LENGTH_SHORT).show(); + // Handle user not logged in scenario + } + } + + + private void fetchApprovedAppointments(String userId) { + db.collection("ApprovedAppointments") + .whereEqualTo("userId", email) // Assuming 'userId' is the field in the Firestore documents + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful()) { + List> appointments = new ArrayList<>(); + for (QueryDocumentSnapshot document : task.getResult()) { + Map appointment = new HashMap<>(document.getData()); + appointment.put("id", document.getId()); + appointments.add(appointment); + } + adapter.setAppointments(appointments); + } else { + Log.w("FetchAppointments", "Error getting documents.", task.getException()); + Toast.makeText(this, "Failed to fetch appointments.", Toast.LENGTH_SHORT).show(); + } + }); + } + + + private void deleteAppointment(String appointmentId) { + db.collection("ApprovedAppointments").document(appointmentId) + .delete() + .addOnSuccessListener(aVoid -> { + Log.d("DeleteAppointment", "Appointment successfully deleted."); + fetchApprovedAppointments(currentUserId); // Refresh the list + }) + .addOnFailureListener(e -> { + Log.w("DeleteAppointment", "Error deleting appointment.", e); + Toast.makeText(this, "Failed to delete appointment.", Toast.LENGTH_SHORT).show(); + }); + } + + class AppointmentAdapter extends RecyclerView.Adapter { + + private List> appointments; + + AppointmentAdapter(List> appointments) { + this.appointments = appointments; + } + + void setAppointments(List> appointments) { + this.appointments = appointments; + notifyDataSetChanged(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cancel_appointment_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + Map appointment = appointments.get(position); + holder.textViewPatientName.setText((String) appointment.get("name")); + holder.textViewPatientEmail.setText((String) appointment.get("email")); + holder.textViewAppointmentDate.setText((String) appointment.get("date")); + holder.textViewAppointmentTime.setText((String) appointment.get("time")); + + holder.buttonCancel.setOnClickListener(v -> { + deleteAppointment((String) appointment.get("id")); + }); + } + + + + @Override + public int getItemCount() { + return appointments.size(); + } + + class ViewHolder extends RecyclerView.ViewHolder { + TextView textViewPatientName; + TextView textViewPatientEmail; + TextView textViewAppointmentDate; + TextView textViewAppointmentTime; + Button buttonCancel; + + ViewHolder(View itemView) { + super(itemView); + textViewPatientName = itemView.findViewById(R.id.textViewPatientName); + textViewPatientEmail = itemView.findViewById(R.id.textViewPatientEmail); + textViewAppointmentDate = itemView.findViewById(R.id.textViewAppointmentDate); + textViewAppointmentTime = itemView.findViewById(R.id.textViewAppointmentTime); + buttonCancel = itemView.findViewById(R.id.buttonCancel); + } + } + } + } + + diff --git a/app/src/main/java/com/example/myapplication/ConnectionClass.java b/app/src/main/java/com/example/myapplication/ConnectionClass.java deleted file mode 100644 index b14dcde..0000000 --- a/app/src/main/java/com/example/myapplication/ConnectionClass.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.myapplication; - - import android.os.StrictMode; - - import java.sql.Connection; - import java.sql.Driver; - import java.sql.DriverManager; - import java.sql.SQLException; - -public class ConnectionClass { - String classes = "net.sourceforge.jtds.jdbc.Driver"; - - protected static String ip= "10.0.2.2"; - protected static String port = "1433"; - protected static String db = "HandMadeHarbour"; - protected static String un = "sa"; - protected static String password = "Wahaj@2711"; - - public Connection CONN(){ - StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); - StrictMode.setThreadPolicy(policy); - Connection conn = null; - try { - Class.forName(classes); - String conUrl = "jdbc:jtds:sqlserver://"+ip+":"+port + ";" + db; - conn = DriverManager.getConnection(conUrl,un,password); - } catch (ClassNotFoundException | SQLException e) { - throw new RuntimeException(e); - } - return conn; - - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/Doctor.java b/app/src/main/java/com/example/myapplication/Doctor.java new file mode 100644 index 0000000..89f1295 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Doctor.java @@ -0,0 +1,39 @@ +package com.example.myapplication; + +public class Doctor { + private String name; + private String email; + private String phone; + private String qualification; + private String experience; + private String category; + private String password; + private String confirmPassword; +private String fee; + // Constructor + public Doctor(String name, String email, String phone, String qualification, String experience, String category, String password, String confirmPassword,String fee) { + this.name = name; + this.email = email; + this.phone = phone; + this.qualification = qualification; + this.experience = experience; + this.category = category; + this.password = password; + this.confirmPassword = confirmPassword; + this.fee=fee; + } + + + // Getters and setters for each field + public String getName() { return name; } + public String getEmail() { return email; } + public String getPhone() { return phone; } + public String getQualification() { return qualification; } + public String getExperience() { return experience; } + public String getCategory() { return category; } + public String getPassword() { return password; } + public String getConfirmPassword() { return confirmPassword; } + public String getFee(){return fee;} + // Required for Firestore to deserialize + public Doctor() {} +} diff --git a/app/src/main/java/com/example/myapplication/DoctorAdapter.java b/app/src/main/java/com/example/myapplication/DoctorAdapter.java new file mode 100644 index 0000000..fd2ffe5 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/DoctorAdapter.java @@ -0,0 +1,118 @@ +package com.example.myapplication; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Filter; +import android.widget.Filterable; +import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import java.util.ArrayList; +import java.util.List; + +public class DoctorAdapter extends RecyclerView.Adapter implements Filterable { + private static List doctorList; + private List doctorListFull; + + public DoctorAdapter(List doctorList) { + this.doctorList = doctorList; + doctorListFull = new ArrayList<>(doctorList); + } + + @NonNull + @Override + public DoctorViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.doctor_item, parent, false); + return new DoctorViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull DoctorViewHolder holder, int position) { + Doctor doctor = doctorList.get(position); + holder.doctorNameTextView.setText(doctor.getName()); + holder.doctorCategoryTextView.setText(doctor.getCategory()); + holder.feeTextView.setText(String.format("Rs. %s", doctor.getFee())); + } + + @Override + public int getItemCount() { + return doctorList.size(); + } + + @Override + public Filter getFilter() { + return doctorFilter; + } + + private Filter doctorFilter = new Filter() { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + List filteredList = new ArrayList<>(); + if (constraint == null || constraint.length() == 0) { + filteredList.addAll(doctorListFull); + } else { + String filterPattern = constraint.toString().toLowerCase().trim(); + + for (Doctor doctor : doctorListFull) { + // Check if the doctor's name or category contains the search pattern + if (doctor.getName().toLowerCase().contains(filterPattern) || + doctor.getCategory().toLowerCase().contains(filterPattern)) { + filteredList.add(doctor); + } + } + } + + FilterResults results = new FilterResults(); + results.values = filteredList; + return results; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + doctorList.clear(); + doctorList.addAll((List) results.values); + notifyDataSetChanged(); + } + }; + + + public void filterList(List filteredList) { + doctorList = filteredList; + notifyDataSetChanged(); + + } + + public static class DoctorViewHolder extends RecyclerView.ViewHolder { + public TextView doctorNameTextView; + public TextView doctorCategoryTextView; + public TextView feeTextView; + public Button bookButton; + + public DoctorViewHolder(@NonNull View itemView) { + super(itemView); + doctorNameTextView = itemView.findViewById(R.id.doctorName); + doctorCategoryTextView = itemView.findViewById(R.id.doctorCategory); + feeTextView = itemView.findViewById(R.id.fee); + bookButton = itemView.findViewById(R.id.bookButton); + + bookButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int position = getAdapterPosition(); + if (position != RecyclerView.NO_POSITION) { + Doctor doctor = doctorList.get(position); + Intent intent = new Intent(itemView.getContext(), ScheduleAppointment.class); + intent.putExtra("doctorName", doctor.getName()); + intent.putExtra("doctorCategory", doctor.getCategory()); + intent.putExtra("fee", doctor.getFee()); + itemView.getContext().startActivity(intent); + } + } + }); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/DoctorProfile.java b/app/src/main/java/com/example/myapplication/DoctorProfile.java new file mode 100644 index 0000000..6633d30 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/DoctorProfile.java @@ -0,0 +1,85 @@ +package com.example.myapplication; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.widget.Button; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; + +public class DoctorProfile extends AppCompatActivity { + + private TextView txtDoctorName; + private String doctorEmail; + + @SuppressLint({"MissingInflatedId", "SetTextI18n"}) + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_doctor_profile); + + // Initialize views + txtDoctorName = findViewById(R.id.txtDoctorName); + TextView txtDoctorCategory = findViewById(R.id.txtDoctorCategory); + TextView txtDoctorPhone = findViewById(R.id.txtDoctorPhone); + TextView txtDoctorQualification = findViewById(R.id.txtDoctorQualification); + TextView txtDoctorExperience = findViewById(R.id.txtDoctorExperience); + TextView txtDoctorEmail = findViewById(R.id.txtdoctorEmail); // Make sure the ID is correct + Button btnEditProfile = findViewById(R.id.btnEditProfile); + Button btnBookAppointment = findViewById(R.id.btnBookAppointment); + Button btnViewPastAppointments = findViewById(R.id.btnViewPastAppointments); + + // Get data from intent + Bundle extras = getIntent().getExtras(); + if (extras != null) { + String name = extras.getString("name", "N/A"); + String category = extras.getString("category", "N/A"); + String phone = extras.getString("phone", "N/A"); + String qualification = extras.getString("qualification", "N/A"); + String experience = extras.getString("experience", "N/A"); + doctorEmail = extras.getString("email", "N/A"); // Save the email to the doctorEmail variable + + // Set data to views + txtDoctorName.setText("Name: " + name); + txtDoctorCategory.setText("Category: " + category); + txtDoctorPhone.setText("Phone #: " + phone); + txtDoctorQualification.setText("Qualification: " + qualification); + txtDoctorExperience.setText("Experience: " + experience); + txtDoctorEmail.setText("Email: " + doctorEmail); // Display the email + } + + btnEditProfile.setOnClickListener(v -> openEditProfileActivity()); + btnBookAppointment.setOnClickListener(v -> openViewPendingAppointmentActivity()); + btnViewPastAppointments.setOnClickListener(v -> openGeneratePrescription()); + } + + private void openEditProfileActivity() + { + Log.d("DoctorProfile", "Sending email: " + doctorEmail); + Intent intent = new Intent(DoctorProfile.this, EditDoctorProfile.class); + intent.putExtra("email", doctorEmail); + startActivity(intent); + } + + private void openViewPendingAppointmentActivity() { + Intent intent = new Intent(DoctorProfile.this, ApproveAppointmentActivity.class); + intent.putExtra("email", doctorEmail); + startActivity(intent); + } + + /*private void openViewPastAppointmentsActivity() { + Intent intent = new Intent(DoctorProfile.this, GeneratePrescription.class); + intent.putExtra("email", doctorEmail); + startActivity(intent); + }*/ + private void openGeneratePrescription() { + Intent intent = new Intent(DoctorProfile.this, GeneratePrescription.class); + intent.putExtra("doctorEmail", doctorEmail); + intent.putExtra("doctorName", txtDoctorName.getText().toString().replace("Name: ", "")); + // Pass default or specific patient data, replace with actual data when available + intent.putExtra("patientEmail", "def@gmail.com"); // Placeholder, replace with actual patient email + intent.putExtra("patientName", "abc"); // Placeholder, replace with actual patient name + startActivity(intent); + } +} diff --git a/app/src/main/java/com/example/myapplication/EditDoctorProfile.java b/app/src/main/java/com/example/myapplication/EditDoctorProfile.java new file mode 100644 index 0000000..8e7b17a --- /dev/null +++ b/app/src/main/java/com/example/myapplication/EditDoctorProfile.java @@ -0,0 +1,88 @@ + +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; +import com.google.firebase.firestore.FirebaseFirestore; + +public class EditDoctorProfile extends AppCompatActivity { + + private EditText editTextName, editTextPhone, editTextQualification, editTextExperience, editTextFee; + private Spinner spinnerCategory; + private Button buttonUpdate; + private String doctorEmail; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_doctor_profile); + + // Initialize views + editTextName = findViewById(R.id.editTextName); + //spinnerCategory = findViewById(R.id.spinnerCategory); + editTextPhone = findViewById(R.id.editTextPhone); + editTextQualification = findViewById(R.id.editTextQualification); + editTextExperience = findViewById(R.id.editTextExperience); + buttonUpdate = findViewById(R.id.btnUpdate); + + // Get email passed from DoctorProfile + Log.d("EditDoctorProfile", "Received email: " + doctorEmail); + Intent intent = getIntent(); + doctorEmail = intent.getStringExtra("email"); + if (doctorEmail == null || doctorEmail.isEmpty()) { + Toast.makeText(this, "Email nottt provided.", Toast.LENGTH_LONG).show(); + return; + } + // Handle update button click + buttonUpdate.setOnClickListener(v -> updateDoctorProfile()); + + + } + private void updateDoctorProfile() { + if (doctorEmail == null || doctorEmail.isEmpty()) { + Toast.makeText(this, "Email not provided.", Toast.LENGTH_LONG).show(); + return; + } + + FirebaseFirestore db = FirebaseFirestore.getInstance(); + String updatedName = editTextName.getText().toString().trim(); + String updatedPhone = editTextPhone.getText().toString().trim(); + String updatedQualification = editTextQualification.getText().toString().trim(); + String updatedExperience = editTextExperience.getText().toString().trim(); + + if (updatedName.isEmpty() || updatedPhone.isEmpty() || updatedQualification.isEmpty() || updatedExperience.isEmpty()) { + Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show(); + return; + } + + if (!updatedPhone.matches("\\d+") || !updatedExperience.matches("\\d+")) { + Toast.makeText(this, "Please enter valid numbers for phone and experience.", Toast.LENGTH_SHORT).show(); + return; + } + + db.collection("doctors") + .whereEqualTo("email", doctorEmail) + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful() && !task.getResult().isEmpty()) { + String docId = task.getResult().getDocuments().get(0).getId(); + db.collection("doctors").document(docId) + .update("name", updatedName, "phone", updatedPhone, + "qualification", updatedQualification, "experience", updatedExperience) + .addOnSuccessListener(aVoid -> Toast.makeText(EditDoctorProfile.this, "Profile Updated successfully.", Toast.LENGTH_SHORT).show()) + .addOnFailureListener(e -> Toast.makeText(EditDoctorProfile.this, "Profile Update Failed: " + e.getMessage(), Toast.LENGTH_LONG).show()); + } else { + Toast.makeText(EditDoctorProfile.this, "No matching email found.", Toast.LENGTH_LONG).show(); + } + }); + } + +} + diff --git a/app/src/main/java/com/example/myapplication/EditPatientProfile.java b/app/src/main/java/com/example/myapplication/EditPatientProfile.java new file mode 100644 index 0000000..e0f6a79 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/EditPatientProfile.java @@ -0,0 +1,95 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.firebase.firestore.FirebaseFirestore; + +public class EditPatientProfile extends AppCompatActivity { + + private EditText editTextName, editTextMedicalHistory; + private DatePicker datePickerAge; + private RadioGroup radioGroupGender; + private Button buttonUpdate; + private String patientEmail; // Variable to store the email + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_patient_profile); + + // Initialize views + editTextName = findViewById(R.id.editTextName); + editTextMedicalHistory = findViewById(R.id.editTextMedicalHistory); + datePickerAge = findViewById(R.id.datePickerAge); + radioGroupGender = findViewById(R.id.radioGroupGender); + buttonUpdate = findViewById(R.id.btnUpdate); + + // Get email passed from PatientProfile + Intent intent = getIntent(); + if (intent != null && intent.hasExtra("email")) { + patientEmail = intent.getStringExtra("email"); // Store the email + } + + // Handle update button click + buttonUpdate.setOnClickListener(v -> updatePatientProfile()); + } + + private void updatePatientProfile() { + FirebaseFirestore db = FirebaseFirestore.getInstance(); + + // Retrieve updated values from views + String updatedName = editTextName.getText().toString().trim(); + String updatedMedicalHistory = editTextMedicalHistory.getText().toString().trim(); + int updatedDay = datePickerAge.getDayOfMonth(); + int updatedMonth = datePickerAge.getMonth(); + int updatedYear = datePickerAge.getYear(); + String updatedGender = ((RadioButton)findViewById(radioGroupGender.getCheckedRadioButtonId())).getText().toString(); + + // Construct the date string or use a Timestamp + String dateOfBirth = updatedDay + "/" + (updatedMonth + 1) + "/" + updatedYear; + + // Query to find the document with the matching email + db.collection("patientsList") + .whereEqualTo("email", patientEmail) + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful()) + { + if (!task.getResult().isEmpty()) { + // Assuming email is unique and only one document should match + String docId = task.getResult().getDocuments().get(0).getId(); + + // Update the found document + db.collection("patientsList").document(docId) + .update("name", updatedName, + "medicalHistory", updatedMedicalHistory, + "dateOfBirth", dateOfBirth, // Updated to use Timestamp + "gender", updatedGender) + .addOnSuccessListener(aVoid -> { + Toast.makeText(EditPatientProfile.this, "Profile Updated successfully.", Toast.LENGTH_SHORT).show(); + Intent resultIntent = new Intent(); + setResult(RESULT_OK, resultIntent); + finish(); + }) + .addOnFailureListener(e -> { + Toast.makeText(EditPatientProfile.this, "Profile Update Failed: " + e.getMessage(), Toast.LENGTH_LONG).show(); + }); + } else { + Toast.makeText(EditPatientProfile.this, "No matching email found.", Toast.LENGTH_LONG).show(); + } + } else { + Toast.makeText(EditPatientProfile.this, "Query failed: " + task.getException().getMessage(), Toast.LENGTH_LONG).show(); + } + }); + } +} diff --git a/app/src/main/java/com/example/myapplication/Feedback.java b/app/src/main/java/com/example/myapplication/Feedback.java new file mode 100644 index 0000000..36b2e44 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Feedback.java @@ -0,0 +1,77 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +public class Feedback extends AppCompatActivity { + + private RadioGroup radioGroup1, radioGroup5, radioGroup3, radioGroup4; + private EditText additionalCommentsInput; + private Button submitFeedbackButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_feedback); + + // Initialize Views + radioGroup1 = findViewById(R.id.radio_group1); + radioGroup5 = findViewById(R.id.radio_group5); + radioGroup3 = findViewById(R.id.radio_group3); + radioGroup4 = findViewById(R.id.radio_group4); + additionalCommentsInput = findViewById(R.id.additional_comments_input); + submitFeedbackButton = findViewById(R.id.submit_feedback_button); + + // Submit Feedback Button Click Listener + submitFeedbackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // Get selected options from RadioGroups + int selectedOption1Id = radioGroup1.getCheckedRadioButtonId(); + int selectedOption5Id = radioGroup5.getCheckedRadioButtonId(); + int selectedOption3Id = radioGroup3.getCheckedRadioButtonId(); + int selectedOption4Id = radioGroup4.getCheckedRadioButtonId(); + + // Check if any option is not selected + if (selectedOption1Id == -1 || selectedOption5Id == -1 || selectedOption3Id == -1 || selectedOption4Id == -1) { + Toast.makeText(Feedback.this, "Please answer all questions", Toast.LENGTH_SHORT).show(); + return; + } + + // Get selected option text + RadioButton selectedOption1 = findViewById(selectedOption1Id); + RadioButton selectedOption5 = findViewById(selectedOption5Id); + RadioButton selectedOption3 = findViewById(selectedOption3Id); + RadioButton selectedOption4 = findViewById(selectedOption4Id); + String option1Text = selectedOption1.getText().toString(); + String option5Text = selectedOption5.getText().toString(); + String option3Text = selectedOption3.getText().toString(); + String option4Text = selectedOption4.getText().toString(); + + // Get additional comments + String additionalComments = additionalCommentsInput.getText().toString(); + + // Display feedback details + displayFeedbackDetails(option1Text, option5Text, option3Text, option4Text, additionalComments); + } + }); + } + + private void displayFeedbackDetails(String option1Text, String option5Text, String option3Text, String option4Text, String additionalComments) { + // Display feedback details (you can replace this with your desired action) + String feedbackDetails = "Question 1: " + option1Text + "\n" + + "Question 5: " + option5Text + "\n" + + "Question 3: " + option3Text + "\n" + + "Question 4: " + option4Text + "\n" + + "Additional Comments: " + additionalComments; + + Toast.makeText(this, feedbackDetails, Toast.LENGTH_LONG).show(); + } +} diff --git a/app/src/main/java/com/example/myapplication/GenerateInvoice.java b/app/src/main/java/com/example/myapplication/GenerateInvoice.java new file mode 100644 index 0000000..62f0f44 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/GenerateInvoice.java @@ -0,0 +1,57 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.ArrayList; +import java.util.List; + +public class GenerateInvoice extends AppCompatActivity { + private RecyclerView recyclerView; + private InvoiceAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_generate_invoice); + + recyclerView = findViewById(R.id.recyclerViewInvoices); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + FirebaseFirestore db = FirebaseFirestore.getInstance(); + + db.collection("ApprovedAppointments") + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful()) { + List invoices = new ArrayList<>(); + for (DocumentSnapshot document : task.getResult()) { + Invoice invoice = new Invoice( + document.getId(), + document.getString("name"), + document.getString("email"), + document.getString("time"), + document.getString("date"), + document.getString("doctorName"), + document.getString("fee"), + document.getString("userId") + ); + invoices.add(invoice); + // Save the Invoice object to the "Invoices" collection + db.collection("Invoices").document(document.getId()).set(invoice); + } + adapter = new InvoiceAdapter(invoices); + recyclerView.setAdapter(adapter); + } else { + Toast.makeText(this, "Error getting documents: " + task.getException(), Toast.LENGTH_SHORT).show(); + } + }); + } +} diff --git a/app/src/main/java/com/example/myapplication/GeneratePrescription.java b/app/src/main/java/com/example/myapplication/GeneratePrescription.java new file mode 100644 index 0000000..a8b9a69 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/GeneratePrescription.java @@ -0,0 +1,341 @@ +////package com.example.myapplication; +//// +////import android.os.Bundle; +////import android.widget.TextView; +////import androidx.appcompat.app.AppCompatActivity; +//// +////public class GeneratePrescription extends AppCompatActivity { +//// +//// private String doctorName; +//// private String patientName; +//// +//// private String doctorEmail; +//// private String patientEmail; +//// // UI elements for displaying names +//// private TextView txtDoctorName; +//// private TextView txtPatientName; +//// +//// @Override +//// protected void onCreate(Bundle savedInstanceState) { +//// super.onCreate(savedInstanceState); +//// setContentView(R.layout.activity_generate_prescription); // Ensure this layout file is updated +//// +//// // Initialize UI components for names +//// txtDoctorName = findViewById(R.id.txtDoctorName); +//// txtPatientName = findViewById(R.id.txtPatientName); +//// +//// // Get data from the intent that started this activity +//// Bundle extras = getIntent().getExtras(); +//// if (extras != null) { +//// doctorEmail = extras.getString("doctorEmail"); +//// patientEmail = extras.getString("patientEmail"); +//// doctorName = extras.getString("doctorName"); +//// patientName = extras.getString("patientName"); +//// +//// // Update UI with the received names +//// txtDoctorName.setText("Doctor: " + doctorName); +//// txtPatientName.setText("Patient: " + patientName); +//// } +//// } +//// +//// +////} +// +//package com.example.myapplication; +// +//import android.content.Intent; +//import android.os.Bundle; +//import android.view.LayoutInflater; +//import android.view.View; +//import android.widget.Button; +//import android.widget.EditText; +//import android.widget.LinearLayout; +//import android.widget.TextView; +//import androidx.appcompat.app.AppCompatActivity; +// +//import org.json.JSONArray; +// +//public class GeneratePrescription extends AppCompatActivity { +// +// private String doctorName; +// private String patientName; +// private String doctorEmail; +// private String patientEmail; +// +// // UI elements for displaying names +// private TextView txtDoctorName; +// private TextView txtPatientName; +// +// // UI elements for item details +// private EditText edtItemName, edtItemQuantity, edtItemDosage; +// private LinearLayout layoutItems; +// private Button btnAddItem, btnStorePrescription; +// +//// @Override +//// protected void onCreate(Bundle savedInstanceState) { +//// super.onCreate(savedInstanceState); +//// setContentView(R.layout.activity_generate_prescription); +//// +//// // Initialize UI components +//// txtDoctorName = findViewById(R.id.txtDoctorName); +//// txtPatientName = findViewById(R.id.txtPatientName); +//// edtItemName = findViewById(R.id.edtItemName); +//// edtItemQuantity = findViewById(R.id.edtItemQuantity); +//// edtItemDosage = findViewById(R.id.edtItemDosage); +//// layoutItems = findViewById(R.id.layoutItems); +//// btnAddItem = findViewById(R.id.btnAddItem); +//// btnStorePrescription = findViewById(R.id.btnStorePrescription); +//// +//// // Set the names from intent extras +//// Bundle extras = getIntent().getExtras(); +//// if (extras != null) { +//// doctorName = extras.getString("doctorName"); +//// patientName = extras.getString("patientName"); +//// txtDoctorName.setText("Doctor: " + doctorName); +//// txtPatientName.setText("Patient: " + patientName); +//// } +//// +//// // Add items to the prescription +//// btnAddItem.setOnClickListener(v -> addItem()); +//// +//// // Store the prescription +//// btnStorePrescription.setOnClickListener(v -> openStorePrescriptionActivity()); +//// } +//@Override +//protected void onCreate(Bundle savedInstanceState) { +// super.onCreate(savedInstanceState); +// setContentView(R.layout.activity_generate_prescription); +// +// // Initialize UI components +// txtDoctorName = findViewById(R.id.txtDoctorName); +// txtPatientName = findViewById(R.id.txtPatientName); +// edtItemName = findViewById(R.id.edtItemName); +// edtItemQuantity = findViewById(R.id.edtItemQuantity); +// edtItemDosage = findViewById(R.id.edtItemDosage); +// layoutItems = findViewById(R.id.layoutItems); +// btnAddItem = findViewById(R.id.btnAddItem); +// btnStorePrescription = findViewById(R.id.btnStorePrescription); +// LinearLayout tableHeader = findViewById(R.id.tableHeader); // Make sure this ID matches your XML +// Button generatePrescriptionButton = findViewById(R.id.btnStorePrescription); +// +// // Set visibility based on whether there are items +// updateVisibility(); +// +// // Set the names from intent extras +// Bundle extras = getIntent().getExtras(); +// if (extras != null) { +// doctorName = extras.getString("doctorName"); +// patientName = extras.getString("patientName"); +// txtDoctorName.setText("Doctor: " + doctorName); +// txtPatientName.setText("Patient: " + patientName); +// } +// +// // Add items to the prescription +// btnAddItem.setOnClickListener(v -> { +// addItem(); +// updateVisibility(); // Update visibility after an item is added +// }); +// +// // Store the prescription +// btnStorePrescription.setOnClickListener(v -> { +// openStorePrescriptionActivity(); +// updateVisibility(); // Update visibility after storing +// }); +//} +// +// private void updateVisibility() { +// LinearLayout tableHeader = findViewById(R.id.tableHeader); // Adjust if using a different ID +// Button generatePrescriptionButton = findViewById(R.id.btnStorePrescription); +// +// // Check if there are any children (items) in the layoutItems +// if (layoutItems.getChildCount() == 0) { +// tableHeader.setVisibility(View.GONE); +// generatePrescriptionButton.setVisibility(View.GONE); +// } else { +// tableHeader.setVisibility(View.VISIBLE); +// generatePrescriptionButton.setVisibility(View.VISIBLE); +// } +// } +// +// private void addItem() { +// String itemName = edtItemName.getText().toString().trim(); +// String itemQuantity = edtItemQuantity.getText().toString().trim(); +// String itemDosage = edtItemDosage.getText().toString().trim(); +// +// if (!itemName.isEmpty() && !itemQuantity.isEmpty() && !itemDosage.isEmpty()) { +// View rowView = LayoutInflater.from(this).inflate(R.layout.prescription_item_row, layoutItems, false); +// TextView txtName = rowView.findViewById(R.id.txtItemName); +// TextView txtQuantity = rowView.findViewById(R.id.txtItemQuantity); +// TextView txtDosage = rowView.findViewById(R.id.txtItemDosage); +// Button btnDelete = rowView.findViewById(R.id.btnDelete); +// +// txtName.setText(itemName); +// txtQuantity.setText(itemQuantity); +// txtDosage.setText(itemDosage); +// btnDelete.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// layoutItems.removeView(rowView); +// } +// }); +// +// layoutItems.addView(rowView); +// // Clear fields +// edtItemName.setText(""); +// edtItemQuantity.setText(""); +// edtItemDosage.setText(""); +// } +// } +// +// private void deleteItem(View rowView) { +// layoutItems.removeView(rowView); +// updateVisibility(); // Update visibility after an item is deleted +// } +// +// private void openStorePrescriptionActivity() { +// JSONArray jsonArray = new JSONArray(); +// for (int i = 0; i < layoutItems.getChildCount(); i++) { +// View child = layoutItems.getChildAt(i); +// String name = ((TextView) child.findViewById(R.id.txtItemName)).getText().toString(); +// String quantity = ((TextView) child.findViewById(R.id.txtItemQuantity)).getText().toString(); +// String dosage = ((TextView) child.findViewById(R.id.txtItemDosage)).getText().toString(); +// String itemDetails = "Name: " + name + ", Quantity: " + quantity + ", Dosage: " + dosage; +// jsonArray.put(itemDetails); +// } +// Intent intent = new Intent(GeneratePrescription.this, StorePrescription.class); +// intent.putExtra("prescriptionData", jsonArray.toString()); +// startActivity(intent); +// } +// +//} +// + +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; + +import org.json.JSONArray; + +public class GeneratePrescription extends AppCompatActivity { + + private String doctorName; + private String patientName; + private String doctorEmail; + private String patientEmail; + + // UI elements for displaying names + private TextView txtDoctorName; + private TextView txtPatientName; + + // UI elements for item details + private EditText edtItemName, edtItemQuantity, edtItemDosage; + private LinearLayout layoutItems; + private Button btnAddItem, btnStorePrescription; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_generate_prescription); + + // Initialize UI components + txtDoctorName = findViewById(R.id.txtDoctorName); + txtPatientName = findViewById(R.id.txtPatientName); + edtItemName = findViewById(R.id.edtItemName); + edtItemQuantity = findViewById(R.id.edtItemQuantity); + edtItemDosage = findViewById(R.id.edtItemDosage); + layoutItems = findViewById(R.id.layoutItems); + btnAddItem = findViewById(R.id.btnAddItem); + btnStorePrescription = findViewById(R.id.btnStorePrescription); + + // Set visibility based on whether there are items + updateVisibility(); + + // Set the names from intent extras + Bundle extras = getIntent().getExtras(); + if (extras != null) { + doctorName = extras.getString("doctorName"); + patientName = extras.getString("patientName"); + txtDoctorName.setText("Doctor: " + doctorName); + txtPatientName.setText("Patient: " + patientName); + } + + // Add items to the prescription + btnAddItem.setOnClickListener(v -> { + addItem(); + updateVisibility(); // Update visibility after an item is added + }); + + // Store the prescription + btnStorePrescription.setOnClickListener(v -> { + openStorePrescriptionActivity(); + updateVisibility(); // Update visibility after storing + }); + } + + private void addItem() { + String itemName = edtItemName.getText().toString().trim(); + String itemQuantity = edtItemQuantity.getText().toString().trim(); + String itemDosage = edtItemDosage.getText().toString().trim(); + + if (!itemName.isEmpty() && !itemQuantity.isEmpty() && !itemDosage.isEmpty()) { + View rowView = LayoutInflater.from(this).inflate(R.layout.prescription_item_row, layoutItems, false); + TextView txtName = rowView.findViewById(R.id.txtItemName); + TextView txtQuantity = rowView.findViewById(R.id.txtItemQuantity); + TextView txtDosage = rowView.findViewById(R.id.txtItemDosage); + Button btnDelete = rowView.findViewById(R.id.btnDelete); + + txtName.setText(itemName); + txtQuantity.setText(itemQuantity); + txtDosage.setText(itemDosage); + btnDelete.setOnClickListener(v -> deleteItem(rowView)); + + layoutItems.addView(rowView); + // Clear fields + edtItemName.setText(""); + edtItemQuantity.setText(""); + edtItemDosage.setText(""); + } + } + + private void deleteItem(View rowView) { + layoutItems.removeView(rowView); + updateVisibility(); // Update visibility after an item is deleted + } + + private void openStorePrescriptionActivity() { + JSONArray jsonArray = new JSONArray(); + for (int i = 0; i < layoutItems.getChildCount(); i++) { + View child = layoutItems.getChildAt(i); + String name = ((TextView) child.findViewById(R.id.txtItemName)).getText().toString(); + String quantity = ((TextView) child.findViewById(R.id.txtItemQuantity)).getText().toString(); + String dosage = ((TextView) child.findViewById(R.id.txtItemDosage)).getText().toString(); + String itemDetails = "Name: " + name + ", Quantity: " + quantity + ", Dosage: " + dosage; + jsonArray.put(itemDetails); + } + Intent intent = new Intent(GeneratePrescription.this, StorePrescription.class); + intent.putExtra("prescriptionData", jsonArray.toString()); + startActivity(intent); + } + + private void updateVisibility() { + LinearLayout tableHeader = findViewById(R.id.tableHeader); + Button generatePrescriptionButton = findViewById(R.id.btnStorePrescription); + + if (layoutItems.getChildCount() == 0) { + tableHeader.setVisibility(View.GONE); + generatePrescriptionButton.setVisibility(View.GONE); + } else { + tableHeader.setVisibility(View.VISIBLE); + generatePrescriptionButton.setVisibility(View.VISIBLE); + } + } +} + diff --git a/app/src/main/java/com/example/myapplication/Invoice.java b/app/src/main/java/com/example/myapplication/Invoice.java new file mode 100644 index 0000000..9da2492 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Invoice.java @@ -0,0 +1,59 @@ +package com.example.myapplication; + +public class Invoice { + private String id; + private String name; // Updated field + private String email; // Updated field + private String doctorname; // Updated field + private String date; // Updated field + private String time; // Updated field + private String fee; // Updated field + private String userId; + + public Invoice() { + // Default constructor required for calls to DataSnapshot.getValue(Invoice.class) + } + + public Invoice(String id, String patientName, String email, String doctorName, String date, String time, String fee, String userId) { + this.id = id; + this.name = patientName; + this.email = email; + this.doctorname = doctorName; + this.date = date; + this.time = time; + this.fee = fee; + this.userId = userId; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public String getDoctorName() { + return doctorname; + } + + public String getDate() { + return date; + } + + public String getTime() { + return time; + } + + public String getFee() { + return fee; + } + + public String getUserId() { + return userId; + } +} diff --git a/app/src/main/java/com/example/myapplication/InvoiceAdapter.java b/app/src/main/java/com/example/myapplication/InvoiceAdapter.java new file mode 100644 index 0000000..9669ff1 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/InvoiceAdapter.java @@ -0,0 +1,68 @@ +package com.example.myapplication; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +public class InvoiceAdapter extends RecyclerView.Adapter { + private List invoices; + private Context context; + + public InvoiceAdapter(List invoices) { + this.context = context; + this.invoices = invoices; + } + + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.invoice_item, parent, true); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + Invoice invoice = invoices.get(position); + holder.nameTextView.setText(invoice.getName()); + holder.emailTextView.setText(invoice.getEmail()); + holder.dateTextView.setText(invoice.getDate()); + holder.timeTextView.setText(invoice.getTime()); + holder.doctorNameTextView.setText(invoice.getDoctorName()); + holder.feeTextView.setText(invoice.getFee()); + holder.userIdTextView.setText(invoice.getUserId()); + } + + @Override + public int getItemCount() { + return invoices.size(); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + TextView nameTextView; + TextView emailTextView; + TextView dateTextView; + TextView timeTextView; + TextView doctorNameTextView; + TextView feeTextView; + TextView userIdTextView; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + nameTextView = itemView.findViewById(R.id.txtPatientName); + emailTextView = itemView.findViewById(R.id.txtPatientEmail); + dateTextView = itemView.findViewById(R.id.txtAppointmentDate); + timeTextView = itemView.findViewById(R.id.txtAppointmentTime); + doctorNameTextView = itemView.findViewById(R.id.doctorNameTextView); + feeTextView = itemView.findViewById(R.id.txtDoctorFee); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/Launchpage.java b/app/src/main/java/com/example/myapplication/Launchpage.java new file mode 100644 index 0000000..29adb25 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Launchpage.java @@ -0,0 +1,45 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import androidx.appcompat.app.AppCompatActivity; + +public class Launchpage extends AppCompatActivity { + + Button btnAdmin, btnPatient, btnDoctor; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_launch_page); + + btnAdmin = findViewById(R.id.btn_admin); + btnPatient = findViewById(R.id.btn_patient); + btnDoctor = findViewById(R.id.btn_doctor); + + btnAdmin.setOnClickListener(v -> navigateToLogin("Admin")); + btnPatient.setOnClickListener(v -> navigateToLogin("Patient")); + btnDoctor.setOnClickListener(v -> navigateToLogin("Doctor")); + } + + private void navigateToLogin(String role) { + Intent intent; + switch (role) { + case "Admin": + intent = new Intent(Launchpage.this, Login_Admin.class); // Intent for Admin login + break; + case "Patient": + intent = new Intent(Launchpage.this, Login_Patient.class); // Intent for Patient login + break; + case "Doctor": + intent = new Intent(Launchpage.this, Login_Doctor.class); // Intent for Doctor login + break; + default: + throw new IllegalStateException("Unexpected role: " + role); + } + intent.putExtra("role", role); + startActivity(intent); + + } + +} diff --git a/app/src/main/java/com/example/myapplication/Login.java b/app/src/main/java/com/example/myapplication/Login.java deleted file mode 100644 index babb074..0000000 --- a/app/src/main/java/com/example/myapplication/Login.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.example.myapplication; - -import android.content.Intent; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; -import android.widget.Button; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.activity.EdgeToEdge; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; -import com.google.android.material.textfield.TextInputEditText; -import com.google.firebase.auth.AuthResult; -import com.google.firebase.auth.FirebaseAuth; -import com.google.firebase.auth.FirebaseUser; - -public class Login extends AppCompatActivity { - - TextInputEditText editTextEmail, editTextPassword; - Button buttonLogin; - FirebaseAuth mAuth; - ProgressBar progressbar; - TextView txtView; - - @Override - public void onStart() { - super.onStart(); - // Check if user is logged in (non-null) and update UI accordingly. - FirebaseUser currentUser = mAuth.getCurrentUser(); - if(currentUser != null){ - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - startActivity(intent); - finish(); - } - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_login); - mAuth=FirebaseAuth.getInstance(); - editTextEmail=findViewById(R.id.email); - editTextPassword=findViewById(R.id.password); - buttonLogin=findViewById(R.id.btn_login); - progressbar=findViewById(R.id.progressbar); - txtView=findViewById(R.id.signupNow); - txtView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent=new Intent(getApplicationContext(), Signup.class); - startActivity(intent); - finish(); - } - }); - - buttonLogin.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - progressbar.setVisibility(View.VISIBLE); - String email, password; - email=String.valueOf(editTextEmail.getText()); - password=String.valueOf(editTextPassword.getText()); - - if(TextUtils.isEmpty(email)){ - Toast.makeText(Login.this, "Enter email", Toast.LENGTH_SHORT).show(); - return; - } - - if(TextUtils.isEmpty(password)){ - Toast.makeText(Login.this, "Enter password", Toast.LENGTH_SHORT).show(); - return; - } - - mAuth.signInWithEmailAndPassword(email, password) - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - progressbar.setVisibility(View.GONE); - if (task.isSuccessful()) { - // Sign in success, update UI with the signed-in user's information - Toast.makeText(getApplicationContext(),"login Successful ",Toast.LENGTH_SHORT).show(); - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - startActivity(intent); - finish(); - } else { - // If sign in fails, display a message to the user. - - Toast.makeText(Login.this, "Authentication failed.", - Toast.LENGTH_SHORT).show(); - - } - } - }); - - - } - }); - - - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/Login_Admin.java b/app/src/main/java/com/example/myapplication/Login_Admin.java new file mode 100644 index 0000000..4da261c --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Login_Admin.java @@ -0,0 +1,75 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; + +import androidx.appcompat.app.AppCompatActivity; +import com.google.android.material.textfield.TextInputEditText; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +import java.util.ResourceBundle; + +public class Login_Admin extends AppCompatActivity { + + TextInputEditText editTextEmail, editTextPassword; + Button buttonLogin; + FirebaseAuth mAuth; + ProgressBar progressbar; + TextView txtView; + // Hardcoded credentials for the admin + private static final String ADMIN_EMAIL = "wahajasif488@gmail.com"; + private static final String ADMIN_PASSWORD = "Wahaj@1"; + + + /* @Override + public void onStart() { + super.onStart(); + // Check if user is logged in (non-null) and update UI accordingly. + FirebaseUser currentUser = mAuth.getCurrentUser(); + if(currentUser != null){ + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + finish(); + } + }*/ + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_login_admin); + mAuth=FirebaseAuth.getInstance(); + editTextEmail=findViewById(R.id.email); + editTextPassword=findViewById(R.id.password); + buttonLogin=findViewById(R.id.btn_login); + progressbar=findViewById(R.id.progressbar); + + + buttonLogin.setOnClickListener(v -> { + progressbar.setVisibility(View.VISIBLE); + String email, password; + email=String.valueOf(editTextEmail.getText()); + password=String.valueOf(editTextPassword.getText()); + + if (!email.equals(ADMIN_EMAIL) || !password.equals(ADMIN_PASSWORD)) { + progressbar.setVisibility(View.GONE); + Toast.makeText(Login_Admin.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getApplicationContext(), "Login Successful", Toast.LENGTH_SHORT).show(); + + Intent intent = new Intent(Login_Admin.this, AdminProfile.class); + startActivity(intent); + finish(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/Login_Doctor.java b/app/src/main/java/com/example/myapplication/Login_Doctor.java new file mode 100644 index 0000000..79cb95c --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Login_Doctor.java @@ -0,0 +1,117 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.android.material.textfield.TextInputEditText; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.FirebaseFirestore; + +public class Login_Doctor extends AppCompatActivity { + + TextInputEditText editTextEmail, editTextPassword; + Button buttonLogin; + FirebaseAuth mAuth; + ProgressBar progressbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_login_doctor); + mAuth = FirebaseAuth.getInstance(); + editTextEmail = findViewById(R.id.email); + editTextPassword = findViewById(R.id.password); + buttonLogin = findViewById(R.id.btn_login); + progressbar = findViewById(R.id.progressbar); + + buttonLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loginUser(); + } + }); + } + + private void loginUser() { + progressbar.setVisibility(View.VISIBLE); + String email = editTextEmail.getText().toString().trim(); + String password = editTextPassword.getText().toString().trim(); + + if (TextUtils.isEmpty(email)) { + Toast.makeText(Login_Doctor.this, "Enter email", Toast.LENGTH_SHORT).show(); + progressbar.setVisibility(View.GONE); + return; + } + + if (TextUtils.isEmpty(password)) { + Toast.makeText(Login_Doctor.this, "Enter password", Toast.LENGTH_SHORT).show(); + progressbar.setVisibility(View.GONE); + return; + } + + mAuth.signInWithEmailAndPassword(email, password) + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + progressbar.setVisibility(View.GONE); + if (task.isSuccessful()) { + FirebaseUser user = mAuth.getCurrentUser(); + if (user != null) { + fetchUserDetailsAndNavigate1(user.getEmail()); + } + } else { + Toast.makeText(Login_Doctor.this, "Authentication failed: " + task.getException().getMessage(), + Toast.LENGTH_SHORT).show(); + } + } + }); + } +private void fetchUserDetailsAndNavigate1(String userEmail) { + FirebaseFirestore db = FirebaseFirestore.getInstance(); + db.collection("doctors") + .whereEqualTo("email", userEmail) + .get() + .addOnSuccessListener(queryDocumentSnapshots -> { + if (!queryDocumentSnapshots.isEmpty()) { + DocumentSnapshot documentSnapshot = queryDocumentSnapshots.getDocuments().get(0); + String name = documentSnapshot.getString("name"); + String category = documentSnapshot.getString("category"); + String qualification = documentSnapshot.getString("qualification"); + String email = documentSnapshot.getString("email"); + String experience=documentSnapshot.getString("experience"); + String phone= documentSnapshot.getString("phone"); + Intent intent = new Intent(Login_Doctor.this, DoctorProfile.class); + intent.putExtra("name", name); + intent.putExtra("category", category); + intent.putExtra("qualification", qualification); + intent.putExtra("experience",experience); + intent.putExtra("phone",phone); + intent.putExtra("email", email); + startActivity(intent); + finish(); + } else { + Toast.makeText(Login_Doctor.this, "Doctor's details not found", Toast.LENGTH_SHORT).show(); + } + }).addOnFailureListener(e -> { + Toast.makeText(Login_Doctor.this, "Failed to fetch doctor details: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + }); + } + } + diff --git a/app/src/main/java/com/example/myapplication/Login_Patient.java b/app/src/main/java/com/example/myapplication/Login_Patient.java new file mode 100644 index 0000000..b85a37b --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Login_Patient.java @@ -0,0 +1,134 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.android.material.textfield.TextInputEditText; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.DocumentSnapshot; + +public class Login_Patient extends AppCompatActivity { + + TextInputEditText editTextEmail, editTextPassword; + Button buttonLogin; + FirebaseAuth mAuth; + ProgressBar progressbar; + TextView txtView; + + /*@Override + public void onStart() { + super.onStart(); + // Check if user is logged in (non-null) and update UI accordingly. + FirebaseUser currentUser = mAuth.getCurrentUser(); + if(currentUser != null){ + Intent intent = new Intent(getApplicationContext(), Launchpage.class); + startActivity(intent); + finish(); + } + }*/ + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_login_patient); + mAuth=FirebaseAuth.getInstance(); + editTextEmail=findViewById(R.id.email); + editTextPassword=findViewById(R.id.password); + buttonLogin=findViewById(R.id.btn_login); + progressbar=findViewById(R.id.progressbar); + txtView=findViewById(R.id.signupNow); + txtView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent=new Intent(getApplicationContext(), SignupPatient.class); + startActivity(intent); + finish(); + } + }); + + buttonLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + progressbar.setVisibility(View.VISIBLE); + String email, password; + email=String.valueOf(editTextEmail.getText()); + password=String.valueOf(editTextPassword.getText()); + + if(TextUtils.isEmpty(email)){ + Toast.makeText(Login_Patient.this, "Enter email", Toast.LENGTH_SHORT).show(); + return; + } + + if(TextUtils.isEmpty(password)){ + Toast.makeText(Login_Patient.this, "Enter password", Toast.LENGTH_SHORT).show(); + return; + } + + mAuth.signInWithEmailAndPassword(email, password) + .addOnCompleteListener(task -> { + progressbar.setVisibility(View.GONE); + if (task.isSuccessful()) { + // Sign in success, update UI with the signed-in user's information + FirebaseUser user = mAuth.getCurrentUser(); + if (user != null) { + // Fetch additional user details from Firestore + fetchUserDetailsAndNavigate(user.getUid()); + } + } else { + // If sign in fails, display a message to the user. + Toast.makeText(Login_Patient.this, "Authentication failed.", + Toast.LENGTH_SHORT).show(); + } + }); + } + }); + } + + // Fetch user details from Firestore and navigate to PatientProfile activity + private void fetchUserDetailsAndNavigate(String userId) { + FirebaseFirestore db = FirebaseFirestore.getInstance(); + DocumentReference userRef = db.collection("patientsList").document(userId); + userRef.get().addOnSuccessListener(documentSnapshot -> { + if (documentSnapshot.exists()) { + // DocumentSnapshot contains the user's details + String name = documentSnapshot.getString("name"); + String dateOfBirth = documentSnapshot.getString("dateOfBirth"); + String gender=documentSnapshot.getString("gender"); + String medicalHistory = documentSnapshot.getString("medicalHistory"); + String email=documentSnapshot.getString("email"); + // Create an intent to navigate to PatientProfile activity and pass the details + Intent intent = new Intent(Login_Patient.this, PatientProfile.class); + + intent.putExtra("name", name); + intent.putExtra("dateOfBirth", dateOfBirth); + intent.putExtra("gender",gender); + intent.putExtra("medicalHistory", medicalHistory); + intent.putExtra("email",email); + startActivity(intent); + finish(); + } else { + // Document does not exist, handle the case accordingly + Toast.makeText(Login_Patient.this, "User details not found", Toast.LENGTH_SHORT).show(); + } + }).addOnFailureListener(e -> { + // Error fetching user details, handle the error + Toast.makeText(Login_Patient.this, "Failed to fetch user details: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + }); + } +} diff --git a/app/src/main/java/com/example/myapplication/MainActivity.java b/app/src/main/java/com/example/myapplication/MainActivity.java index 19023b2..c7bc5f4 100644 --- a/app/src/main/java/com/example/myapplication/MainActivity.java +++ b/app/src/main/java/com/example/myapplication/MainActivity.java @@ -1,108 +1,110 @@ package com.example.myapplication; +import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; -import android.widget.Toast; import androidx.activity.EdgeToEdge; -import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; -import com.google.firestore.v1.WriteResult; -import java.sql.Connection; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutionException; public class MainActivity extends AppCompatActivity { - FirebaseAuth auth; - Button btn; - TextView textView; - FirebaseUser user; - Connection con; - String str; - FirebaseFirestore db = FirebaseFirestore.getInstance(); + private static final String TAG = "MainActivity"; + + private FirebaseAuth auth; + private Button btn1, btn2, btn3, btn4, btn5, btnx; + private TextView textView; + private FirebaseUser user; + @SuppressLint("MissingInflatedId") @Override - protected void onCreate(Bundle savedInstanceState){ + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); - auth=FirebaseAuth.getInstance(); - btn=findViewById(R.id.logout); - textView=findViewById(R.id.user_details); - user=auth.getCurrentUser(); - if(user==null){ - Intent intent =new Intent(getApplicationContext(),Login.class); + auth = FirebaseAuth.getInstance(); + btn1 = findViewById(R.id.logout); + btn2 = findViewById(R.id.Doctor); + btn3 = findViewById(R.id.Appointment); + btn4 = findViewById(R.id.viewAppointmentsButton); + btn5 = findViewById(R.id.viewUpcomingAppointments); + btnx = findViewById(R.id.btnYourAppointments); + textView = findViewById(R.id.user_details); + user = auth.getCurrentUser(); + + if (user == null) { + Intent intent = new Intent(getApplicationContext(), Launchpage.class); startActivity(intent); finish(); - - } - else{ - textView.setText(user.getEmail()); + } else { + // Fetch user's name and email from Firestore + FirebaseFirestore db = FirebaseFirestore.getInstance(); + DocumentReference docRef = db.collection("patientsList").document(user.getUid()); + docRef.get().addOnSuccessListener(documentSnapshot -> { + if (documentSnapshot.exists()) { + String name = documentSnapshot.getString("name"); + String email = documentSnapshot.getString("email"); + // Display user's name and email + textView.setText("Name: " + name + "\nEmail: " + email); + } else { + Log.d(TAG, "No such document"); + } + }).addOnFailureListener(e -> { + Log.d(TAG, "Error fetching document: " + e); + }); } - btn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FirebaseAuth.getInstance().signOut(); - Intent intent =new Intent(getApplicationContext(),Login.class); - startActivity(intent); - finish(); - } + btn1.setOnClickListener(v -> { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), AddDoctor.class); + startActivity(intent); + finish(); }); - - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - + btn2.setOnClickListener(v -> { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), SearchDoctor.class); + startActivity(intent); + finish(); }); - Button button = findViewById(R.id.button); - - // Set click listener on the button - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // Call method to add data to Firestore - addDataToFirestore("doctors", "John Doe"); - } + btn3.setOnClickListener(v -> { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), ScheduleAppointment.class); + startActivity(intent); + finish(); + }); + btn4.setOnClickListener(v -> { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), ApproveAppointmentActivity.class); + startActivity(intent); + finish(); + }); + btn5.setOnClickListener(v -> { + FirebaseAuth.getInstance().signOut(); + Intent intent = new Intent(getApplicationContext(), UpcomingAppointmentsActivity.class); + startActivity(intent); + finish(); + }); + btnx.setOnClickListener(v -> { + navigateToCancel(); }); - } - private void addDataToFirestore(String collectionName, String name) { - Map city = new HashMap<>(); - city.put("name", "Los Angeles"); - db.collection(collectionName).document("LA") - .set(city) - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(Void aVoid) { - Toast.makeText(MainActivity.this, "Data added to Firestore", Toast.LENGTH_SHORT).show(); - } - }) - .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception e) { - Toast.makeText(MainActivity.this, "Failed to add data to Firestore", Toast.LENGTH_SHORT).show(); + } - } - }); + private void navigateToCancel() { + Intent intent = new Intent(getApplicationContext(), CancelAppointmentsActivity.class); + startActivity(intent); + finish(); } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/Message.java b/app/src/main/java/com/example/myapplication/Message.java new file mode 100644 index 0000000..88019d8 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/Message.java @@ -0,0 +1,44 @@ +package com.example.myapplication; +public class Message { + private String text; + private long timestamp; + private String senderName; + private String senderEmail; + private String senderId; + + public Message() { + // Default constructor required for Firebase + } + + public Message(String text, long timestamp, String senderName, String senderEmail, String senderId) { + this.text = text; + this.timestamp = timestamp; + this.senderName = senderName; + this.senderEmail = senderEmail; + this.senderId = senderId; + } + + public String getText() { + return text; + } + + public long getTimestamp() { + return timestamp; + } + + public String getSenderName() { + return senderName; + } + + public String getSenderEmail() { + return senderEmail; + } + + public String getSenderId() { + return senderId; + } + @Override + public String toString() { + return text + "\n" + senderName; // Display text and sender name in the ListView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/OnDoctorClickListener1.java b/app/src/main/java/com/example/myapplication/OnDoctorClickListener1.java new file mode 100644 index 0000000..f8ee32a --- /dev/null +++ b/app/src/main/java/com/example/myapplication/OnDoctorClickListener1.java @@ -0,0 +1,5 @@ +package com.example.myapplication; + +public interface OnDoctorClickListener1 { + void onDoctorClick(Doctor doctor); +} diff --git a/app/src/main/java/com/example/myapplication/PatientProfile.java b/app/src/main/java/com/example/myapplication/PatientProfile.java new file mode 100644 index 0000000..cd75025 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/PatientProfile.java @@ -0,0 +1,94 @@ +package com.example.myapplication; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import android.widget.TextView; +import android.widget.TableLayout; +import android.widget.TableRow; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +public class PatientProfile extends AppCompatActivity { + + private static final int EDIT_PROFILE_REQUEST = 1; // Define a request code + + private TextView txtPatientName, txtPatientAge, txtPatientGender, txtPatientMedicalHistory; + private Button btnEditProfile, btnBookAppointment, btnViewPastAppointments; + private String patientEmail; + private TextView txtPatientEmail; + + @SuppressLint({"SetTextI18n", "MissingInflatedId"}) + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_patient_profile); + + // Initialize views + txtPatientName = findViewById(R.id.txtPatientName); + txtPatientAge = findViewById(R.id.txtPatientAge); + txtPatientGender = findViewById(R.id.txtPatientGender); + txtPatientMedicalHistory = findViewById(R.id.txtPatientMedicalHistory); + txtPatientEmail = findViewById(R.id.txtPatientEmail); // Initialize email TextView + btnEditProfile = findViewById(R.id.btnEditProfile); + btnBookAppointment = findViewById(R.id.btnBookAppointment); + btnViewPastAppointments = findViewById(R.id.btnCancelAppointment); + + // Get data from intent + Bundle extras = getIntent().getExtras(); + if (extras != null) { + String name = extras.getString("name", "N/A"); + String age = extras.getString("dateOfBirth", "N/A"); + String gender = extras.getString("gender", "N/A"); + String medicalHistory = extras.getString("medicalHistory", "No history provided."); + patientEmail = extras.getString("email", "Email not provided"); // Handle null email + + // Set data to views + txtPatientName.setText("Name: " + name); + txtPatientAge.setText("Date of Birth: " + age); + txtPatientGender.setText("Gender: " + gender); + txtPatientMedicalHistory.setText("Medical History: " + medicalHistory); + txtPatientEmail.setText("Email: " + patientEmail); // Set email text + } + + // Handle button clicks + btnEditProfile.setOnClickListener(v -> openEditProfileActivity()); + btnBookAppointment.setOnClickListener(v -> openBookAppointmentActivity()); + btnViewPastAppointments.setOnClickListener(v -> openViewPastAppointmentsActivity()); + } + + private void openEditProfileActivity() { + Intent intent = new Intent(PatientProfile.this, EditPatientProfile.class); + intent.putExtra("name", txtPatientName.getText().toString()); + intent.putExtra("dateOfBirth", txtPatientAge.getText().toString()); + intent.putExtra("gender", txtPatientGender.getText().toString()); + intent.putExtra("medicalHistory", txtPatientMedicalHistory.getText().toString()); + intent.putExtra("email", patientEmail); // Pass the email to the next activity + startActivityForResult(intent, EDIT_PROFILE_REQUEST); // Start activity for result + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == EDIT_PROFILE_REQUEST && resultCode == RESULT_OK) { + // Refresh profile data here + // For example, you can re-fetch the data from intent extras and update the views + } + } + + private void openBookAppointmentActivity() { + Intent intent = new Intent(this, SearchDoctor.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + finish(); + } + + private void openViewPastAppointmentsActivity() { + Intent intent = new Intent(this, CancelAppointmentsActivity.class); + intent.putExtra("USER_EMAIL", patientEmail); // Correctly passing the patient's email + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + finish(); + } +} diff --git a/app/src/main/java/com/example/myapplication/ScheduleAppointment.java b/app/src/main/java/com/example/myapplication/ScheduleAppointment.java new file mode 100644 index 0000000..9dacbe8 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ScheduleAppointment.java @@ -0,0 +1,166 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.widget.TextView; +import android.widget.TimePicker; +import android.widget.Toast; +import android.widget.Button; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.graphics.Insets; +import android.app.DatePickerDialog; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +public class ScheduleAppointment extends AppCompatActivity { + + private FirebaseFirestore db; + private FirebaseAuth mAuth; + private TextView datePickerEditText; + private TimePicker timePicker; + private boolean dateSelected = false; + private boolean timeSelected = false; + private Button confirmButton; + private String doctorName,doctorCategory,fee; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_schedule_appointment); + TextView doctorNameTextView = findViewById(R.id.doctorNameTextView); + TextView doctorCategoryTextView = findViewById(R.id.doctorCategoryTextView); + TextView feeTextView = findViewById(R.id.feeTextView); + + doctorName = getIntent().getStringExtra("doctorName"); + doctorCategory = getIntent().getStringExtra("doctorCategory"); + fee = getIntent().getStringExtra("fee"); + + doctorNameTextView.setText(doctorName); + doctorCategoryTextView.setText(doctorCategory); + feeTextView.setText(String.format("Rs. %s", fee)); + // Initialize Firestore and FirebaseAuth + db = FirebaseFirestore.getInstance(); + mAuth = FirebaseAuth.getInstance(); + + datePickerEditText = findViewById(R.id.datePickerEditText); + timePicker = findViewById(R.id.timePicker); + confirmButton = findViewById(R.id.confirmButton); + confirmButton.setEnabled(false); + + datePickerEditText.setOnClickListener(v -> showDatePicker()); + timePicker.setOnTimeChangedListener((view, hourOfDay, minute) -> { + timeSelected = true; + checkAndDisplayMessage(); + }); + + confirmButton.setOnClickListener(v -> { + if (dateSelected && timeSelected) { + showMessageAndNavigate("Request forwarded"); + } + }); + + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + // Immediately check the user status + checkCurrentUser(); + } + + private void checkCurrentUser() { + FirebaseUser user = mAuth.getCurrentUser(); + if (user == null) { + Toast.makeText(this, "User not logged in", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(this, Login_Patient.class); + startActivity(intent); + finish(); + } + } + + private void showDatePicker() { + final Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + int day = calendar.get(Calendar.DAY_OF_MONTH); + + DatePickerDialog datePickerDialog = new DatePickerDialog(this, + (view, year1, monthOfYear, dayOfMonth) -> { + String selectedDate = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year1; + datePickerEditText.setText(selectedDate); + dateSelected = true; + }, year, month, day); + datePickerDialog.show(); + } + + private void showMessageAndNavigate(String message) { + FirebaseUser user = mAuth.getCurrentUser(); + if (user != null) { + String userId = user.getEmail(); + String userEmail = user.getEmail(); + + // Retrieve the user's name from the patientsList collection + db.collection("patientsList").document(user.getUid()) + .get() + .addOnSuccessListener(documentSnapshot -> + { + if (documentSnapshot.exists()) { + String userName = documentSnapshot.getString("name"); + + // Continue with appointment scheduling + String selectedDate = datePickerEditText.getText().toString(); + String selectedTime = timePicker.getHour() + ":" + timePicker.getMinute(); + + Map appointment = new HashMap<>(); + appointment.put("userId",userId); + appointment.put("name", userName); + appointment.put("email", userEmail); + appointment.put("date", selectedDate); + appointment.put("time", selectedTime); + appointment.put("fee",fee); + appointment.put("doctorname",doctorName); + + db.collection("pendingAppointments").add(appointment) + .addOnSuccessListener(documentReference -> { + Toast.makeText(ScheduleAppointment.this, "Appointment saved!", Toast.LENGTH_SHORT).show(); + navigateToMain(); + }) + .addOnFailureListener(e -> Toast.makeText(ScheduleAppointment.this, "Error saving appointment", Toast.LENGTH_SHORT).show()); + } else { + Toast.makeText(ScheduleAppointment.this, "User not found in patient list", Toast.LENGTH_SHORT).show(); + } + }) + .addOnFailureListener(e -> Toast.makeText(ScheduleAppointment.this, "Error fetching user data", Toast.LENGTH_SHORT).show()); + } else { + Toast.makeText(this, "User not logged in", Toast.LENGTH_SHORT).show(); + } + } + + + private void navigateToMain() { + Intent intent = new Intent(this, PatientProfile.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + + + finish(); + } + + private void checkAndDisplayMessage() { + if (dateSelected && timeSelected) { + confirmButton.setEnabled(true); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/SearchDoctor.java b/app/src/main/java/com/example/myapplication/SearchDoctor.java new file mode 100644 index 0000000..23639d7 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/SearchDoctor.java @@ -0,0 +1,75 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.widget.EditText; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.QueryDocumentSnapshot; +import java.util.ArrayList; +import java.util.List; + +public class SearchDoctor extends AppCompatActivity { + private RecyclerView recyclerView; + private DoctorAdapter adapter; + private List doctorList = new ArrayList<>(); + private EditText searchQueryEditText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_search_doctor); + + recyclerView = findViewById(R.id.doctorsRecyclerView); + searchQueryEditText = findViewById(R.id.searchQueryEditText); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new DoctorAdapter(doctorList); + recyclerView.setAdapter(adapter); + + // Access Firebase Firestore instance + FirebaseFirestore db = FirebaseFirestore.getInstance(); + + // Get all doctors from the "doctors" collection + db.collection("doctors").get().addOnCompleteListener(task -> { + if (task.isSuccessful()) { + doctorList.clear(); // Clear the existing data in doctorList + for (QueryDocumentSnapshot document : task.getResult()) { + Doctor doctor = document.toObject(Doctor.class); // Convert the Firestore document into a Doctor object + doctorList.add(doctor); // Add the doctor to the list + } + adapter.notifyDataSetChanged(); // Notify the adapter that the data has changed + } else { + Log.w("SearchDoctorActivity", "Error getting documents: ", task.getException()); + } + }); + + // Implement search functionality + searchQueryEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + filterDoctors(s.toString()); + } + + @Override + public void afterTextChanged(Editable s) {} + }); + } + + // Filter doctors based on the search query + private void filterDoctors(String query) { + List filteredList = new ArrayList<>(); + for (Doctor doctor : doctorList) { + if (doctor.getName().toLowerCase().contains(query.toLowerCase())) { + filteredList.add(doctor); + } + } + adapter.filterList(filteredList); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/Signup.java b/app/src/main/java/com/example/myapplication/Signup.java deleted file mode 100644 index 19d6e8e..0000000 --- a/app/src/main/java/com/example/myapplication/Signup.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.example.myapplication; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; -import android.widget.Button; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.activity.EdgeToEdge; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; -import com.google.android.material.textfield.TextInputEditText; -import com.google.firebase.auth.AuthResult; -import com.google.firebase.auth.FirebaseAuth; -import com.google.firebase.auth.FirebaseAuthException; -import com.google.firebase.auth.FirebaseUser; -import com.google.firebase.firestore.auth.FirebaseAuthCredentialsProvider; - - -public class Signup extends AppCompatActivity { - - TextInputEditText editTextEmail, editTextPassword; - Button buttonSignup; - FirebaseAuth mAuth; - ProgressBar progressbar; - - TextView txtView; - - @Override - public void onStart() { - super.onStart(); - // Check if user is logged in (non-null) and update UI accordingly. - FirebaseUser currentUser = mAuth.getCurrentUser(); - if(currentUser != null){ - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - startActivity(intent); - finish(); - } - } - - @SuppressLint("MissingInflatedId") - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_signup); - mAuth=FirebaseAuth.getInstance(); - editTextEmail=findViewById(R.id.email); - editTextPassword=findViewById(R.id.password); - buttonSignup=findViewById(R.id.btn_signup); - progressbar=findViewById(R.id.progressbar); - txtView=findViewById(R.id.loginNow); - txtView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent=new Intent(getApplicationContext(), Login.class); - startActivity(intent); - finish(); - } - }); - - buttonSignup.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - progressbar.setVisibility(View.VISIBLE); - String email, password; - email=String.valueOf(editTextEmail.getText()); - password=String.valueOf(editTextPassword.getText()); - - if(TextUtils.isEmpty(email)){ - Toast.makeText(Signup.this, "Enter email", Toast.LENGTH_SHORT).show(); - return; - } - - if(TextUtils.isEmpty(password)){ - Toast.makeText(Signup.this, "Enter password", Toast.LENGTH_SHORT).show(); - return; - } - - - mAuth.createUserWithEmailAndPassword(email, password) - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - progressbar.setVisibility(View.GONE); - if (task.isSuccessful()) { - - Toast.makeText(Signup.this, "Account created.", - Toast.LENGTH_SHORT).show(); - Intent intent =new Intent(getApplicationContext(),Login.class); - startActivity(intent); - finish(); - - } else { - // If sign in fails, display a message to the user. - Toast.makeText(Signup.this, "Authentication failed.", - Toast.LENGTH_SHORT).show(); - } - } - }); - - } - }); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/SignupDoctor.java b/app/src/main/java/com/example/myapplication/SignupDoctor.java new file mode 100644 index 0000000..b1588c8 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/SignupDoctor.java @@ -0,0 +1,122 @@ +package com.example.myapplication; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.android.material.textfield.TextInputEditText; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class SignupDoctor extends AppCompatActivity { + + private TextInputEditText editTextName, editTextEmail, editTextPassword, editTextConfirmPassword; + private Button buttonSignup; + private FirebaseAuth mAuth; + private ProgressBar progressbar; + private TextView loginNow; + + @Override + protected void onStart() { + super.onStart(); + FirebaseUser currentUser = mAuth.getCurrentUser(); + if (currentUser != null) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(intent); + finish(); + } + } + + @SuppressLint("MissingInflatedId") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_signup_doctor); + + mAuth = FirebaseAuth.getInstance(); + + editTextName = findViewById(R.id.name); + editTextEmail = findViewById(R.id.email); + editTextPassword = findViewById(R.id.password); + editTextConfirmPassword = findViewById(R.id.confirmPassword); + buttonSignup = findViewById(R.id.btn_signup); + progressbar = findViewById(R.id.progressbar); + loginNow = findViewById(R.id.loginNow); // Make sure you have this TextView in your layout + + loginNow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(SignupDoctor.this, Login_Admin.class); + startActivity(intent); + finish(); + } + }); + + buttonSignup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final String name = editTextName.getText().toString().trim(); + final String email = editTextEmail.getText().toString().trim(); + final String password = editTextPassword.getText().toString().trim(); + final String confirmPassword = editTextConfirmPassword.getText().toString().trim(); + + if (TextUtils.isEmpty(name)) { + Toast.makeText(SignupDoctor.this, "Enter name", Toast.LENGTH_SHORT).show(); + return; + } + + if (TextUtils.isEmpty(email)) { + Toast.makeText(SignupDoctor.this, "Enter email", Toast.LENGTH_SHORT).show(); + return; + } + + if (TextUtils.isEmpty(password)) { + Toast.makeText(SignupDoctor.this, "Enter password", Toast.LENGTH_SHORT).show(); + return; + } + + if (TextUtils.isEmpty(confirmPassword)) { + Toast.makeText(SignupDoctor.this, "Confirm your password", Toast.LENGTH_SHORT).show(); + return; + } + + if (!password.equals(confirmPassword)) { + Toast.makeText(SignupDoctor.this, "Passwords do not match", Toast.LENGTH_SHORT).show(); + return; + } + + progressbar.setVisibility(View.VISIBLE); + + mAuth.createUserWithEmailAndPassword(email, password) + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + progressbar.setVisibility(View.GONE); + if (task.isSuccessful()) { + Toast.makeText(SignupDoctor.this, "Account created successfully.", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(getApplicationContext(), Login_Admin.class); + startActivity(intent); + finish(); + } else { + Toast.makeText(SignupDoctor.this, "Authentication failed: " + task.getException().getMessage(), Toast.LENGTH_LONG).show(); + } + } + }); + } + }); + } +} diff --git a/app/src/main/java/com/example/myapplication/SignupPatient.java b/app/src/main/java/com/example/myapplication/SignupPatient.java new file mode 100644 index 0000000..89893d9 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/SignupPatient.java @@ -0,0 +1,114 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.ProgressBar; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; +import com.google.android.material.textfield.TextInputEditText; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.FirebaseFirestore; +import java.util.HashMap; +import java.util.Map; + +public class SignupPatient extends AppCompatActivity { + + TextInputEditText editTextName, editTextEmail, editTextPassword, editTextMedicalHistory; + DatePicker datePickerAge; + RadioGroup radioGroupGender; + Button buttonSignup; + ProgressBar progressBar; + FirebaseAuth mAuth; + FirebaseFirestore db; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_signup_patient); + + mAuth = FirebaseAuth.getInstance(); + db = FirebaseFirestore.getInstance(); // Initialize Firestore + + // Initialize views + editTextName = findViewById(R.id.editTextName); + editTextEmail = findViewById(R.id.editTextEmail); + editTextPassword = findViewById(R.id.editTextPassword); + datePickerAge = findViewById(R.id.datePickerAge); + radioGroupGender = findViewById(R.id.radioGroupGender); + editTextMedicalHistory = findViewById(R.id.editTextMedicalHistory); + buttonSignup = findViewById(R.id.btn_signup); + progressBar = findViewById(R.id.progressBar); + + buttonSignup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + progressBar.setVisibility(View.VISIBLE); // Show progress bar + buttonSignup.setVisibility(View.GONE); // Hide button + signUpPatient(); + } + }); + } + + private void signUpPatient() { + final String name = editTextName.getText().toString().trim(); + final String email = editTextEmail.getText().toString().trim(); + String password = editTextPassword.getText().toString().trim(); + final String medicalHistory = editTextMedicalHistory.getText().toString().trim(); + final String dob = datePickerAge.getDayOfMonth() + "/" + (datePickerAge.getMonth() + 1) + "/" + datePickerAge.getYear(); + final String gender = ((RadioButton) findViewById(radioGroupGender.getCheckedRadioButtonId())).getText().toString(); + + if (name.isEmpty() || email.isEmpty() || password.isEmpty() || dob.isEmpty() || gender.isEmpty() || medicalHistory.isEmpty()) { + Toast.makeText(this, "All fields are required.", Toast.LENGTH_SHORT).show(); + progressBar.setVisibility(View.GONE); + buttonSignup.setVisibility(View.VISIBLE); + return; + } + + mAuth.createUserWithEmailAndPassword(email, password) + .addOnCompleteListener(this, task -> { + if (task.isSuccessful()) { + // User creation successful, now save data to Firestore + String userId = mAuth.getCurrentUser().getUid(); // Get user ID + + // Create a map to store user data + Map user = new HashMap<>(); + user.put("name", name); + user.put("email", email); + user.put("dateOfBirth", dob); + user.put("gender", gender); + user.put("medicalHistory", medicalHistory); + + // Store user data in Firestore + db.collection("patientsList") + .document(userId) + .set(user) + .addOnSuccessListener(aVoid -> { + Toast.makeText(SignupPatient.this, "Account created and data stored successfully.", Toast.LENGTH_SHORT).show(); + redirectToLogin(); + }) + .addOnFailureListener(e -> { + Toast.makeText(SignupPatient.this, "Failed to store data: " + e.getMessage(), Toast.LENGTH_LONG).show(); + progressBar.setVisibility(View.GONE); + buttonSignup.setVisibility(View.VISIBLE); + }); + } else { + // User creation failed, show error message + Toast.makeText(SignupPatient.this, "Authentication failed: " + task.getException().getMessage(), Toast.LENGTH_LONG).show(); + progressBar.setVisibility(View.GONE); + buttonSignup.setVisibility(View.VISIBLE); + } + }); + } + + private void redirectToLogin() { + Intent intent = new Intent(this, Login_Patient.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + finish(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/StorePrescription.java b/app/src/main/java/com/example/myapplication/StorePrescription.java new file mode 100644 index 0000000..f8da031 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/StorePrescription.java @@ -0,0 +1,36 @@ +package com.example.myapplication; + +import android.os.Bundle; +import android.widget.LinearLayout; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import org.json.JSONArray; +import org.json.JSONException; + +public class StorePrescription extends AppCompatActivity { + + private LinearLayout llPrescriptionList; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_store_prescription); + + llPrescriptionList = findViewById(R.id.llPrescriptionList); + + // Assuming you pass the prescription data as a serialized JSON array + String jsonData = getIntent().getStringExtra("prescriptionData"); + try { + JSONArray jsonArray = new JSONArray(jsonData); + for (int i = 0; i < jsonArray.length(); i++) { + String itemDetails = jsonArray.getString(i); // This should be formatted data + TextView textView = new TextView(this); + textView.setText(itemDetails); + textView.setPadding(10, 10, 10, 10); + llPrescriptionList.addView(textView); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/UpcomingAppointmentsActivity.java b/app/src/main/java/com/example/myapplication/UpcomingAppointmentsActivity.java new file mode 100644 index 0000000..d123494 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/UpcomingAppointmentsActivity.java @@ -0,0 +1,157 @@ +package com.example.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.QueryDocumentSnapshot; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UpcomingAppointmentsActivity extends AppCompatActivity { + + private UpcomingAppointmentAdapter adapter; + private final List> appointments = new ArrayList<>(); + private final FirebaseFirestore db = FirebaseFirestore.getInstance(); + private final FirebaseAuth mAuth = FirebaseAuth.getInstance(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_upcoming_appointments); + + RecyclerView recyclerView = findViewById(R.id.recyclerViewAppointments); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapter = new UpcomingAppointmentAdapter(appointments); + recyclerView.setAdapter(adapter); + + Button okButton = findViewById(R.id.buttonOk); + okButton.setOnClickListener(v -> { + FirebaseUser user = mAuth.getCurrentUser(); + // fetchUserDetailsAndNavigate1(user.getEmail()); + }); + + fetchAppointments(); + } + + private void fetchAppointments() { + db.collection("ApprovedAppointments") + .get() + .addOnCompleteListener(task -> { + if (task.isSuccessful()) { + appointments.clear(); + for (QueryDocumentSnapshot document : task.getResult()) { + Map appointment = new HashMap<>(document.getData()); + appointment.put("id", document.getId()); + appointments.add(appointment); + } + adapter.notifyDataSetChanged(); + } else { + Log.w("FetchUpcomingAppointments", "Error getting documents.", task.getException()); + } + }); + } + + private static class UpcomingAppointmentAdapter extends RecyclerView.Adapter { + + private List> appointments; + + UpcomingAppointmentAdapter(List> appointments) { + this.appointments = appointments; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.upcoming_appointment_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + Map appointment = appointments.get(position); + holder.textViewPatientName.setText((String) appointment.get("name")); + holder.textViewPatientEmail.setText((String) appointment.get("email")); + holder.textViewAppointmentDate.setText((String) appointment.get("date")); + holder.textViewAppointmentTime.setText((String) appointment.get("time")); + + holder.buttonDone.setOnClickListener(v -> { + removeAppointment(position); // Remove the appointment from the list when "Done" is clicked + }); + } + + @Override + public int getItemCount() { + return appointments.size(); + } + + private void removeAppointment(int position) { + if (position < appointments.size()) { + appointments.remove(position); + notifyItemRemoved(position); + notifyItemRangeChanged(position, appointments.size()); // Update the range after item removal + } + } + + class ViewHolder extends RecyclerView.ViewHolder { + TextView textViewPatientName, textViewPatientEmail, textViewAppointmentDate, textViewAppointmentTime; + Button buttonDone; + + ViewHolder(View itemView) { + super(itemView); + textViewPatientName = itemView.findViewById(R.id.textViewPatientName); + textViewPatientEmail = itemView.findViewById(R.id.textViewPatientEmail); + textViewAppointmentDate = itemView.findViewById(R.id.textViewAppointmentDate); + textViewAppointmentTime = itemView.findViewById(R.id.textViewAppointmentTime); + buttonDone = itemView.findViewById(R.id.buttonDone); + } + } + } + /*private void fetchUserDetailsAndNavigate1(String userEmail) { + FirebaseFirestore db = FirebaseFirestore.getInstance(); + db.collection("doctors") + .whereEqualTo("email", userEmail) + .get() + .addOnSuccessListener(queryDocumentSnapshots -> { + if (!queryDocumentSnapshots.isEmpty()) { + DocumentSnapshot documentSnapshot = queryDocumentSnapshots.getDocuments().get(0); + String name = documentSnapshot.getString("name"); + String category = documentSnapshot.getString("category"); + String qualification = documentSnapshot.getString("qualification"); + String email = documentSnapshot.getString("email"); + String experience=documentSnapshot.getString("experience"); + String phone= documentSnapshot.getString("phone"); + Intent intent = new Intent(UpcomingAppointmentsActivity.this, DoctorProfile.class); + intent.putExtra("name", name); + intent.putExtra("category", category); + intent.putExtra("qualification", qualification); + intent.putExtra("experience",experience); + intent.putExtra("phone",phone); + intent.putExtra("email", email); + startActivity(intent); + finish(); + } else { + Toast.makeText(UpcomingAppointmentsActivity.this, "Doctor's details not found", Toast.LENGTH_SHORT).show(); + } + }).addOnFailureListener(e -> { + Toast.makeText(UpcomingAppointmentsActivity.this, "Failed to fetch doctor details: " + e.getMessage(), Toast.LENGTH_SHORT).show(); + });*/ + } diff --git a/app/src/main/res/color/grey.xml b/app/src/main/res/color/grey.xml new file mode 100644 index 0000000..a8b409b --- /dev/null +++ b/app/src/main/res/color/grey.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/cell_border.xml b/app/src/main/res/drawable/cell_border.xml new file mode 100644 index 0000000..ae1b6a2 --- /dev/null +++ b/app/src/main/res/drawable/cell_border.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_calendar.xml b/app/src/main/res/drawable/ic_calendar.xml new file mode 100644 index 0000000..a8b409b --- /dev/null +++ b/app/src/main/res/drawable/ic_calendar.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 07d5da9..0000000 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d1..0000000 --- a/app/src/main/res/drawable/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_profile_placeholder.xml b/app/src/main/res/drawable/ic_profile_placeholder.xml new file mode 100644 index 0000000..5394b3b --- /dev/null +++ b/app/src/main/res/drawable/ic_profile_placeholder.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/item_background_with_divider.xml b/app/src/main/res/drawable/item_background_with_divider.xml new file mode 100644 index 0000000..241cd9c --- /dev/null +++ b/app/src/main/res/drawable/item_background_with_divider.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/message_background.xml b/app/src/main/res/drawable/message_background.xml new file mode 100644 index 0000000..9173b72 --- /dev/null +++ b/app/src/main/res/drawable/message_background.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_button.xml b/app/src/main/res/drawable/rounded_button.xml new file mode 100644 index 0000000..6a08b56 --- /dev/null +++ b/app/src/main/res/drawable/rounded_button.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_edittext.xml b/app/src/main/res/drawable/rounded_edittext.xml new file mode 100644 index 0000000..94de1bc --- /dev/null +++ b/app/src/main/res/drawable/rounded_edittext.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/drawable/table_border.xml b/app/src/main/res/drawable/table_border.xml new file mode 100644 index 0000000..4f1b858 --- /dev/null +++ b/app/src/main/res/drawable/table_border.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/app/src/main/res/layout/activity_add_doctor.xml b/app/src/main/res/layout/activity_add_doctor.xml new file mode 100644 index 0000000..6c04299 --- /dev/null +++ b/app/src/main/res/layout/activity_add_doctor.xml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +