Index: backend/src/main/java/medora/repository/AdminRepository.java
===================================================================
--- backend/src/main/java/medora/repository/AdminRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/AdminRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,8 @@
+package medora.repository;
+
+import medora.models.domain.Admin;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface AdminRepository extends JpaRepository<Admin, Long> {
+}
+
Index: backend/src/main/java/medora/repository/AllergyRepository.java
===================================================================
--- backend/src/main/java/medora/repository/AllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/AllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,45 @@
+package medora.repository;
+
+import medora.models.domain.Allergies;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface AllergyRepository extends JpaRepository<Allergies, Long> {
+//UC011 – Record Allergies
+//A doctor records patient allergies in the medical record.
+// Use save() method from JpaRepository
+
+// Find allergies by name
+    Optional<Allergies> findByNameIgnoreCase(String name);
+
+    // Helper: Get all allergies for a patient
+    @Query("""
+        SELECT a FROM Allergies a
+        WHERE a IN (
+            SELECT pa.allergy FROM PatientAllergy pa
+            WHERE pa.patient.patientId = :patientId
+        )
+    """)
+    List<Allergies> findByPatientId(@Param("patientId") Long patientId);
+
+    // Helper: Get all allergies recorded in a medical record
+    @Query("""
+        SELECT a FROM Allergies a
+        WHERE a IN (
+            SELECT mra.allergy FROM MedicalRecordAllergies mra
+             WHERE mra.medicalRecord.recordId = :recordId
+        )
+    """)
+    List<Allergies> findByMedicalRecordId(@Param("recordId") Long recordId);
+
+    // Helper: Search allergies by name (case-insensitive)
+    @Query("""
+        SELECT a FROM Allergies a
+        WHERE LOWER(a.name) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<Allergies> findByNameContainingIgnoreCase(@Param("name") String name);
+}
Index: backend/src/main/java/medora/repository/AppointmentRepository.java
===================================================================
--- backend/src/main/java/medora/repository/AppointmentRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/AppointmentRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,97 @@
+package medora.repository;
+
+import medora.models.domain.Appointment;
+import medora.models.enums.AppointmentStatus;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.List;
+
+public interface AppointmentRepository extends JpaRepository<Appointment, Long> {
+
+    /**
+     * Get appointments for a patient
+     */
+    List<Appointment> findByPatientPatientIdOrderByAppointmentDateAscAppointmentTimeAsc(
+            Long patientId
+    );
+
+    /**
+     * Get appointments for a doctor
+     */
+    List<Appointment> findByDoctorDoctorIdOrderByAppointmentDateAscAppointmentTimeAsc(
+            Long doctorId
+    );
+
+    /**
+     * Get doctor schedule for a specific date
+     */
+    List<Appointment> findByDoctorDoctorIdAndAppointmentDateOrderByAppointmentTimeAsc(
+            Long doctorId,
+            LocalDate appointmentDate
+    );
+
+    /**
+     * Check if doctor already has appointment at this slot
+     */
+    boolean existsByDoctorDoctorIdAndAppointmentDateAndAppointmentTimeAndStatusNot(
+            Long doctorId,
+            LocalDate appointmentDate,
+            LocalTime appointmentTime,
+            AppointmentStatus status
+    );
+
+    /**
+     * Check duplicate patient appointment
+     */
+    boolean existsByPatientPatientIdAndDoctorDoctorIdAndAppointmentDateAndAppointmentTimeAndStatusNot(
+            Long patientId,
+            Long doctorId,
+            LocalDate appointmentDate,
+            LocalTime appointmentTime,
+            AppointmentStatus status
+    );
+
+    /**
+     * UC007 – Cancel Appointment
+     */
+    @Transactional
+    @Modifying
+    @Query("""
+        UPDATE Appointment a
+        SET a.status = 'CANCELLED'
+        WHERE a.appointmentId = :appointmentId
+    """)
+    void cancelAppointment(@Param("appointmentId") Long appointmentId);
+
+    /**
+     * Get active appointments for patient
+     */
+    @Query("""
+        SELECT a FROM Appointment a
+        WHERE a.patient.patientId = :patientId
+        AND a.status != 'CANCELLED'
+        ORDER BY a.appointmentDate DESC, a.appointmentTime DESC
+    """)
+    List<Appointment> getActiveAppointmentsForPatient(
+            @Param("patientId") Long patientId
+    );
+
+    /**
+     * Get active appointments for doctor
+     */
+    @Query("""
+        SELECT a FROM Appointment a
+        WHERE a.doctor.doctorId = :doctorId
+        AND a.status != 'CANCELLED'
+        ORDER BY a.appointmentDate DESC, a.appointmentTime DESC
+    """)
+    List<Appointment> getActiveAppointmentsForDoctor(
+            @Param("doctorId") Long doctorId
+    );
+}
Index: backend/src/main/java/medora/repository/BillingLabTestsRepository.java
===================================================================
--- backend/src/main/java/medora/repository/BillingLabTestsRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/BillingLabTestsRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,28 @@
+package medora.repository;
+
+import medora.models.domain.BillingLabTests;
+import medora.models.domain.id.BillingLabTestId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public interface BillingLabTestsRepository extends JpaRepository<BillingLabTests, BillingLabTestId> {
+
+    // Find all lab tests for a billing record
+    @Query("""
+        SELECT blt FROM BillingLabTests blt
+        WHERE blt.billing.billId = :billId
+    """)
+    List<BillingLabTests> findByBillingBillId(@Param("billId") Long billId);
+
+    // Calculate total cost of lab tests for a billing record
+    @Query("""
+        SELECT COALESCE(SUM(blt.labTest.cost), 0) FROM BillingLabTests blt
+        WHERE blt.billing.billId = :billId
+    """)
+    BigDecimal calculateTotalCostForBilling(@Param("billId") Long billId);
+}
+
Index: backend/src/main/java/medora/repository/BillingProceduresRepository.java
===================================================================
--- backend/src/main/java/medora/repository/BillingProceduresRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/BillingProceduresRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,28 @@
+package medora.repository;
+
+import medora.models.domain.BillingProcedures;
+import medora.models.domain.id.BillingProcedureId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public interface BillingProceduresRepository extends JpaRepository<BillingProcedures, BillingProcedureId> {
+
+    // Find all procedures for a billing record
+    @Query("""
+        SELECT bp FROM BillingProcedures bp
+        WHERE bp.billing.billId = :billId
+    """)
+    List<BillingProcedures> findByBillingBillId(@Param("billId") Long billId);
+
+    // Calculate total cost of procedures for a billing record
+    @Query("""
+        SELECT COALESCE(SUM(bp.procedure.cost), 0) FROM BillingProcedures bp
+        WHERE bp.billing.billId = :billId
+    """)
+    BigDecimal calculateTotalCostForBilling(@Param("billId") Long billId);
+}
+
Index: backend/src/main/java/medora/repository/BillingRepository.java
===================================================================
--- backend/src/main/java/medora/repository/BillingRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/BillingRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,81 @@
+package medora.repository;
+
+
+import medora.models.domain.Billing;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public interface BillingRepository extends JpaRepository<Billing, Long> {
+
+    // UC020 – Generate Billing Record
+    // UC021 – Record Payment Status
+    // UC022 – View Billing History
+
+    // UC022 – View Billing History (Patient view - through medical record)
+    @Query("""
+        SELECT b FROM Billing b
+        WHERE b.medicalRecord.patient.patientId = :patientId
+        ORDER BY b.paymentDate DESC
+    """)
+    List<Billing> findByPatientPatientId(Long patientId);
+
+    // UC022 – View Billing History (Admin view)
+    List<Billing> findByAdminAdminId(Long adminId);
+
+    // UC021 – Record Payment Status
+    @Transactional
+    @Modifying
+    @Query("""
+        UPDATE Billing b
+        SET b.paymentStatus = :status
+        WHERE b.billId = :billId
+    """)
+    void updatePaymentStatus(
+            @Param("billId") Long billId,
+            @Param("status") String status
+    );
+
+    // UC020 – Helper to calculate total cost for a medical record
+    @Query(value = """
+        SELECT COALESCE(SUM(p.cost), 0) + COALESCE(SUM(l.cost), 0) AS total_cost
+        FROM medical_records mr
+        LEFT JOIN medical_record_procedures mrp ON mr.record_id = mrp.record_id
+        LEFT JOIN procedures p ON mrp.procedure_id = p.procedure_id
+        LEFT JOIN medical_record_lab_results mrl ON mr.record_id = mrl.record_id
+        LEFT JOIN lab_results lr ON mrl.result_id = lr.result_id
+        LEFT JOIN lab_tests l ON lr.test_id = l.test_id
+        WHERE mr.record_id = :recordId
+    """, nativeQuery = true)
+    BigDecimal calculateTotalCostForMedicalRecord(@Param("recordId") Long recordId);
+
+    // Helper: Get billing records by payment status
+    @Query("""
+        SELECT b FROM Billing b
+        WHERE b.paymentStatus = :status
+        ORDER BY b.paymentDate DESC
+    """)
+    List<Billing> findByPaymentStatus(@Param("status") String status);
+
+    // Helper: Get unpaid bills for a patient
+    @Query("""
+        SELECT b FROM Billing b
+        WHERE b.medicalRecord.patient.patientId = :patientId
+        AND b.paymentStatus != 'PAID'
+        ORDER BY b.paymentDate DESC
+    """)
+    List<Billing> findUnpaidBillsForPatient(@Param("patientId") Long patientId);
+
+    // Helper: Get all bills for a patient sorted by date
+    @Query("""
+        SELECT b FROM Billing b
+        WHERE b.medicalRecord.patient.patientId = :patientId
+        ORDER BY b.paymentDate DESC
+    """)
+    List<Billing> findBillingHistoryForPatient(@Param("patientId") Long patientId);
+}
Index: backend/src/main/java/medora/repository/DepartmentRepository.java
===================================================================
--- backend/src/main/java/medora/repository/DepartmentRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/DepartmentRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,18 @@
+package medora.repository;
+
+import medora.models.domain.Departments;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.Optional;
+
+public interface DepartmentRepository extends JpaRepository<Departments, Long> {
+
+    // UC023 – View Departments
+    @Query("""
+        SELECT d FROM Departments d
+        WHERE d.departmentName = :departmentName
+    """)
+    Optional<Departments> findByDepartmentName(String departmentName);
+}
+
Index: backend/src/main/java/medora/repository/DiagnosisRepository.java
===================================================================
--- backend/src/main/java/medora/repository/DiagnosisRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/DiagnosisRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,36 @@
+package medora.repository;
+
+
+import medora.models.domain.Diagnosis;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface DiagnosisRepository extends JpaRepository<Diagnosis, Long> {
+//UC009 – Record Diagnosis
+   // A doctor adds a diagnosis to a patient’s medical record.
+   // Use save() method from JpaRepository to create new diagnoses
+
+    // Find all diagnoses for a specific patient
+    List<Diagnosis> findByPatientPatientId(Long patientId);
+
+    // Find all diagnoses recorded by a specific doctor
+    List<Diagnosis> findByDoctorDoctorId(Long doctorId);
+
+    // Helper: Search diagnoses by name (for UC026)
+    @Query("""
+        SELECT d FROM Diagnosis d
+        WHERE LOWER(d.name) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<Diagnosis> findByNameContainingIgnoreCase(@Param("name") String name);
+
+    // Helper: Find diagnoses for a specific patient by name
+    @Query("""
+        SELECT d FROM Diagnosis d
+        WHERE d.patient.patientId = :patientId
+        AND LOWER(d.name) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<Diagnosis> findByPatientAndNameContaining(@Param("patientId") Long patientId, @Param("name") String name);
+}
Index: backend/src/main/java/medora/repository/DoctorRepository.java
===================================================================
--- backend/src/main/java/medora/repository/DoctorRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/DoctorRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,78 @@
+package medora.repository;
+
+
+import medora.models.domain.Doctors;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface DoctorRepository extends JpaRepository<Doctors, Long> {
+
+    // UC023 – View Departments (see DepartmentRepository)
+    // UC024 – View Doctors by Department
+    // UC025 – View Doctor Profile
+
+    // UC024 – Find all doctors assigned to a specific department
+    List<Doctors> findByDepartmentDepartmentId(Long departmentId);
+
+    // UC025 – View Doctor Profile with full details
+    @Query("""
+        SELECT d FROM Doctors d
+        LEFT JOIN FETCH d.specialization
+        LEFT JOIN FETCH d.level
+        LEFT JOIN FETCH d.department
+        WHERE d.doctorId = :doctorId
+    """)
+    Optional<Doctors> getDoctorProfile(@Param("doctorId") Long doctorId);
+
+    // Helper: Find doctors by specialization
+    @Query("""
+        SELECT d FROM Doctors d
+        WHERE d.specialization.specializationId = :specializationId
+    """)
+    List<Doctors> findBySpecializationId(@Param("specializationId") Long specializationId);
+
+    // Helper: Find doctors by level
+    @Query("""
+        SELECT d FROM Doctors d
+        WHERE d.level.levelId = :levelId
+    """)
+    List<Doctors> findByLevelId(@Param("levelId") Long levelId);
+
+    // Helper: Find doctors by name
+    @Query("""
+        SELECT d FROM Doctors d
+        WHERE LOWER(d.firstName) LIKE LOWER(CONCAT('%', :name, '%'))
+           OR LOWER(d.lastName) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<Doctors> findByNameContainingIgnoreCase(@Param("name") String name);
+
+    // Helper: Find doctors in a department with a specific specialization
+    @Query("""
+        SELECT d FROM Doctors d
+        WHERE d.department.departmentId = :departmentId
+        AND d.specialization.specializationId = :specializationId
+    """)
+    List<Doctors> findByDepartmentAndSpecialization(
+            @Param("departmentId") Long departmentId,
+            @Param("specializationId") Long specializationId
+    );
+
+    // Helper: Get doctor by email (for login/verification)
+    Optional<Doctors> findByEmailAddressIgnoreCase(String emailAddress);
+    // UC025 – View Doctor Profile
+    Optional<Doctors> findByEmailAddress(String emailAddress);
+
+
+
+
+    // filter by specialization
+    List<Doctors> findBySpecializationSpecializationId(Long specializationId);
+
+    // filter by level
+    List<Doctors> findByLevelLevelId(Long levelId);
+}
+
Index: backend/src/main/java/medora/repository/LabResultsRepository.java
===================================================================
--- backend/src/main/java/medora/repository/LabResultsRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/LabResultsRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,36 @@
+package medora.repository;
+
+import medora.models.domain.LabResults;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface LabResultsRepository extends JpaRepository<LabResults, Long> {
+
+    // UC014 – Store Lab Results
+    // Use save() method from JpaRepository instead of raw SQL INSERT
+    // This properly manages entity lifecycle and relationships
+
+    // UC015 – Link Medical Data - Find lab results for a specific test
+    List<LabResults> findByLabTestTestId(Long testId);
+
+    // Helper: Find all results for a specific medical record
+    @Query("""
+        SELECT lr FROM LabResults lr
+        WHERE lr IN (
+            SELECT mrlr.labResult FROM MedicalRecordLabResults mrlr
+            WHERE mrlr.medicalRecord.recordId = :recordId
+        )
+    """)
+    List<LabResults> findByMedicalRecordId(@Param("recordId") Long recordId);
+
+    // Helper: Find results by lab test ordered by date
+    @Query("""
+        SELECT lr FROM LabResults lr
+        WHERE lr.labTest.testId = :testId
+        ORDER BY lr.resultDate DESC
+    """)
+    List<LabResults> findLatestResultsByTest(@Param("testId") Long testId);
+}
Index: backend/src/main/java/medora/repository/LabTechnicianRepository.java
===================================================================
--- backend/src/main/java/medora/repository/LabTechnicianRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/LabTechnicianRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,7 @@
+package medora.repository;
+
+import medora.models.domain.LabTechnician;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface LabTechnicianRepository extends JpaRepository<LabTechnician, Long> {
+}
Index: backend/src/main/java/medora/repository/LabTestRepository.java
===================================================================
--- backend/src/main/java/medora/repository/LabTestRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/LabTestRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,32 @@
+package medora.repository;
+
+import medora.models.domain.LabTests;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface LabTestRepository extends JpaRepository<LabTests, Long> {
+
+    // UC013 – Record Lab Test Request
+    // Use save() method from JpaRepository
+
+    // Helper: Find lab test by name
+    Optional<LabTests> findByTestNameIgnoreCase(String testName);
+
+    // Helper: Search lab tests by name
+    @Query("""
+        SELECT lt FROM LabTests lt
+        WHERE LOWER(lt.testName) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<LabTests> findByNameContainingIgnoreCase(@Param("name") String name);
+
+    // Helper: Get all available lab tests
+    @Query("""
+        SELECT lt FROM LabTests lt
+        ORDER BY lt.testName ASC
+    """)
+    List<LabTests> findAllLabTests();
+}
Index: backend/src/main/java/medora/repository/MedicalRecordAllergyRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalRecordAllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalRecordAllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,19 @@
+package medora.repository;
+
+import medora.models.domain.MedicalRecordAllergies;
+import medora.models.domain.id.MedicalRecordAllergyId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface MedicalRecordAllergyRepository extends JpaRepository<MedicalRecordAllergies, MedicalRecordAllergyId> {
+
+    List<MedicalRecordAllergies> findByMedicalRecordRecordId(Long medicalRecordId);
+
+    boolean existsByMedicalRecordRecordIdAndAllergyAllergyId(Long medicalRecordId, Long allergyId);
+
+    List<MedicalRecordAllergies> findByMedicalRecordRecordIdAndAllergyAllergyId(Long medicalRecordId, Long allergyId);
+}
+
Index: backend/src/main/java/medora/repository/MedicalRecordLabResultRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalRecordLabResultRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalRecordLabResultRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,32 @@
+package medora.repository;
+
+
+
+import medora.models.domain.MedicalRecordLabResults;
+import medora.models.domain.id.MedicalRecordLabResultId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface MedicalRecordLabResultRepository
+        extends JpaRepository<MedicalRecordLabResults, MedicalRecordLabResultId> {
+
+    // UC015 – Link lab result to medical record
+    @Modifying
+    @Query(value = """
+        INSERT INTO medical_record_lab_results (record_id, result_id)
+        VALUES (:recordId, :resultId)
+    """, nativeQuery = true)
+    void linkLabResult(
+            @Param("recordId") Long recordId,
+            @Param("resultId") Long resultId
+    );
+
+    // Find all lab results linked to a medical record
+    List<MedicalRecordLabResults> findByMedicalRecordRecordId(Long recordId);
+}
+
+
Index: backend/src/main/java/medora/repository/MedicalRecordProcedureRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalRecordProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalRecordProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,31 @@
+package medora.repository;
+
+
+import medora.models.domain.MedicalRecordProcedures;
+import medora.models.domain.id.MedicalRecordProcedureId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface MedicalRecordProcedureRepository
+        extends JpaRepository<MedicalRecordProcedures, MedicalRecordProcedureId> {
+
+    @Modifying
+    @Query(value = """
+        INSERT INTO medical_record_procedures (record_id, procedure_id)
+        VALUES (:recordId, :procedureId)
+    """, nativeQuery = true)
+    void linkProcedure(
+            @Param("recordId") Long recordId,
+            @Param("procedureId") Long procedureId
+    );
+
+    // Find all procedures linked to a medical record
+    List<MedicalRecordProcedures> findByMedicalRecordRecordId(Long recordId);
+
+    // Check if a procedure is already linked to a medical record
+    boolean existsByMedicalRecordRecordIdAndProcedureProcedureId(Long recordId, Long procedureId);
+}
Index: backend/src/main/java/medora/repository/MedicalRecordRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalRecordRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalRecordRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,40 @@
+package medora.repository;
+
+import medora.models.domain.MedicalRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.time.LocalDate;
+import java.util.List;
+import java.util.Optional;
+
+public interface MedicalRecordRepository extends JpaRepository<MedicalRecord, Long> {
+
+    // UC005 – View Medical Record (Full history)
+    // UC008 – Access Medical Record
+    Optional<MedicalRecord> findByPatientPatientId(Long patientId);
+
+    // UC026 – Search Medical Records (with filters: name, EMBG, diagnosis, date range)
+    @Query("""
+        SELECT DISTINCT mr
+        FROM MedicalRecord mr
+        JOIN mr.patient p
+        LEFT JOIN Diagnosis d ON d.patient.patientId = p.patientId
+        WHERE
+            (:name IS NULL OR LOWER(p.firstName) LIKE LOWER(CONCAT('%', :name, '%'))
+                           OR LOWER(p.lastName) LIKE LOWER(CONCAT('%', :name, '%')))
+        AND (:embg IS NULL OR p.embg = :embg)
+        AND (:diagnosis IS NULL OR LOWER(d.name) LIKE LOWER(CONCAT('%', :diagnosis, '%')))
+        AND (:fromDate IS NULL OR mr.recordId >= :fromDate)
+        AND (:toDate IS NULL OR mr.recordId <= :toDate)
+    """)
+    List<MedicalRecord> searchMedicalRecords(
+            @Param("name") String name,
+            @Param("embg") String embg,
+            @Param("diagnosis") String diagnosis,
+            @Param("fromDate") LocalDate fromDate,
+            @Param("toDate") LocalDate toDate
+    );
+
+}
Index: backend/src/main/java/medora/repository/MedicalRecordSymptomRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalRecordSymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalRecordSymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,19 @@
+package medora.repository;
+
+import medora.models.domain.MedicalRecordSymptoms;
+import medora.models.domain.id.MedicalRecordSymptomId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface MedicalRecordSymptomRepository extends JpaRepository<MedicalRecordSymptoms, MedicalRecordSymptomId> {
+
+    List<MedicalRecordSymptoms> findByMedicalRecordRecordId(Long medicalRecordId);
+
+    boolean existsByMedicalRecordRecordIdAndSymptomSymptomId(Long medicalRecordId, Long symptomId);
+
+    List<MedicalRecordSymptoms> findByMedicalRecordRecordIdAndSymptomSymptomId(Long medicalRecordId, Long symptomId);
+}
+
Index: backend/src/main/java/medora/repository/MedicalReportRepository.java
===================================================================
--- backend/src/main/java/medora/repository/MedicalReportRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/MedicalReportRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,30 @@
+package medora.repository;
+
+
+import medora.models.domain.MedicalReport;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface MedicalReportRepository extends JpaRepository<MedicalReport, Long> {
+
+    // UC018 – Create Medical Report
+    // Use save() method from JpaRepository instead of raw SQL INSERT
+    // This properly manages entity lifecycle and relationships
+
+    // UC005 – Retrieve medical reports for a medical record
+    List<MedicalReport> findByMedicalRecordRecordId(Long recordId);
+
+    // Retrieve reports created by a specific doctor
+    List<MedicalReport> findByDoctorDoctorId(Long doctorId);
+
+    // Helper: Get reports for a medical record ordered by date
+    @Query("""
+        SELECT mr FROM MedicalReport mr
+         WHERE mr.medicalRecord.recordId = :recordId
+        ORDER BY mr.reportDate DESC
+    """)
+    List<MedicalReport> getReportsForRecord(@Param("recordId") Long recordId);
+}
Index: backend/src/main/java/medora/repository/PatientRepository.java
===================================================================
--- backend/src/main/java/medora/repository/PatientRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/PatientRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,27 @@
+package medora.repository;
+
+import medora.models.domain.Patient;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface PatientRepository extends JpaRepository<Patient, Long> {
+
+    // UC004 – View Patient Profile
+    // Find patient by EMBG (unique identifier)
+    Optional<Patient> findByEmbg(String embg);
+
+    // Find patient by email for login/contact purposes
+    Optional<Patient> findByEmailAddress(String emailAddress);
+
+    // UC026 – Helper for medical record search by patient name
+    @Query("""
+        SELECT p FROM Patient p
+        WHERE LOWER(p.firstName) LIKE LOWER(CONCAT('%', :name, '%'))
+           OR LOWER(p.lastName) LIKE LOWER(CONCAT('%', :name, '%'))
+    """)
+    List<Patient> findByNameContainingIgnoreCase(@Param("name") String name);
+}
Index: backend/src/main/java/medora/repository/PerformedLabTestRepository.java
===================================================================
--- backend/src/main/java/medora/repository/PerformedLabTestRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/PerformedLabTestRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,14 @@
+package medora.repository;
+
+
+import medora.models.domain.PerformedLabTests;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+
+public interface PerformedLabTestRepository extends JpaRepository<PerformedLabTests, Long> {
+
+    List<PerformedLabTests> findByPatientPatientId(Long patientId);
+
+    List<PerformedLabTests> findByDoctorDoctorId(Long doctorId);
+}
Index: backend/src/main/java/medora/repository/PerformedProcedureRepository.java
===================================================================
--- backend/src/main/java/medora/repository/PerformedProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/PerformedProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,47 @@
+package medora.repository;
+
+
+
+import medora.models.domain.PerformedProcedures;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface PerformedProcedureRepository extends JpaRepository<PerformedProcedures, Long> {
+
+    // UC016 – Record Procedure Entry
+    // Use save() method from JpaRepository instead of raw SQL INSERT
+
+    // UC017 – Record Procedure Outcome
+    @Transactional
+    @Modifying
+    @Query("""
+        UPDATE PerformedProcedures pp
+        SET pp.notes = :notes
+        WHERE pp.performedId = :id
+    """)
+    void updateProcedureOutcome(
+            @Param("id") Long id,
+            @Param("notes") String notes
+    );
+
+    // Helper: Get all procedures performed on a patient
+    List<PerformedProcedures> findByPatientPatientId(Long patientId);
+
+    // Helper: Get all procedures performed by a doctor
+    List<PerformedProcedures> findByDoctorDoctorId(Long doctorId);
+
+    // Helper: Get procedures for a specific diagnosis
+    List<PerformedProcedures> findByDiagnosisDiagnosisId(Long diagnosisId);
+
+    // UC015 – Link Medical Data - Get procedures linked to a medical record
+    @Query("""
+        SELECT mrp.procedure FROM MedicalRecordProcedures mrp
+        WHERE mrp.medicalRecord.recordId = :recordId
+    """)
+    List<PerformedProcedures> findByMedicalRecordId(@Param("recordId") Long recordId);
+}
Index: backend/src/main/java/medora/repository/PrescriptionMedicalRecordRepository.java
===================================================================
--- backend/src/main/java/medora/repository/PrescriptionMedicalRecordRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/PrescriptionMedicalRecordRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,44 @@
+package medora.repository;
+
+import medora.models.domain.PrescriptionMedicalRecord;
+import medora.models.domain.id.PrescriptionMedicalRecordId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface PrescriptionMedicalRecordRepository 
+        extends JpaRepository<PrescriptionMedicalRecord, PrescriptionMedicalRecordId> {
+
+    // UC012 – Record Prescription
+    // Find all prescriptions linked to a medical record
+    @Query("""
+        SELECT pmr FROM PrescriptionMedicalRecord pmr
+        WHERE pmr.medicalRecord.recordId = :recordId
+    """)
+    List<PrescriptionMedicalRecord> findByMedicalRecordRecordId(@Param("recordId") Long recordId);
+
+    // Find a specific prescription for a medical record
+    @Query("""
+        SELECT pmr FROM PrescriptionMedicalRecord pmr
+        WHERE pmr.medicalRecord.recordId = :recordId
+        AND pmr.prescription.prescriptionId = :prescriptionId
+    """)
+    PrescriptionMedicalRecord findByMedicalRecordAndPrescription(
+            @Param("recordId") Long recordId,
+            @Param("prescriptionId") Long prescriptionId
+    );
+
+    // Find all prescriptions for a medical record by prescription ID
+    @Query("""
+        SELECT pmr FROM PrescriptionMedicalRecord pmr
+        WHERE pmr.medicalRecord.recordId = :recordId
+        AND pmr.prescription.prescriptionId = :prescriptionId
+    """)
+    List<PrescriptionMedicalRecord> findByMedicalRecordRecordIdAndPrescriptionPrescriptionId(
+            @Param("recordId") Long recordId,
+            @Param("prescriptionId") Long prescriptionId
+    );
+}
+
Index: backend/src/main/java/medora/repository/PrescriptionRepository.java
===================================================================
--- backend/src/main/java/medora/repository/PrescriptionRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/PrescriptionRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,51 @@
+package medora.repository;
+
+
+
+import medora.models.domain.Prescriptions;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface PrescriptionRepository extends JpaRepository<Prescriptions, Long> {
+
+    // UC012 – Record Prescription
+    // A doctor prescribes medication linked to the medical record.
+    // Use save() method from JpaRepository
+
+    // Search prescriptions by medication name
+    List<Prescriptions> findByMedicationNameContainingIgnoreCase(String name);
+
+    // Helper: Get all prescriptions for a specific medical record
+    @Query("""
+        SELECT p FROM Prescriptions p
+        WHERE p IN (
+            SELECT pmr.prescription FROM PrescriptionMedicalRecord pmr
+            WHERE pmr.medicalRecord.recordId = :recordId
+        )
+    """)
+    List<Prescriptions> findByMedicalRecordId(@Param("recordId") Long recordId);
+
+    // Helper: Get all prescriptions for a patient
+    @Query("""
+        SELECT p FROM Prescriptions p
+        WHERE p IN (
+            SELECT pmr.prescription FROM PrescriptionMedicalRecord pmr
+            WHERE pmr.medicalRecord.patient.patientId = :patientId
+        )
+    """)
+    List<Prescriptions> findByPatientId(@Param("patientId") Long patientId);
+
+    // Helper: Get active prescriptions for a patient (by duration)
+    @Query("""
+        SELECT p FROM Prescriptions p
+        WHERE p IN (
+            SELECT pmr.prescription FROM PrescriptionMedicalRecord pmr
+            WHERE pmr.medicalRecord.patient.patientId = :patientId
+            AND pmr.duration IS NOT NULL
+        )
+    """)
+    List<Prescriptions> findActivePrescrriptionsForPatient(@Param("patientId") Long patientId);
+}
Index: backend/src/main/java/medora/repository/ProcedureRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ProcedureRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,8 @@
+package medora.repository;
+
+import medora.models.domain.Procedure;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface ProcedureRepository extends JpaRepository<Procedure, Long> {
+}
+
Index: backend/src/main/java/medora/repository/ReferralRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ReferralRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ReferralRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,40 @@
+package medora.repository;
+
+import medora.models.domain.Referrals;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface ReferralRepository extends JpaRepository<Referrals, Long> {
+
+    // UC019 – Create Referral Record
+    // Use save() method from JpaRepository instead of raw SQL INSERT
+    // This properly manages entity lifecycle and relationships
+
+    // Find referrals associated with a medical record
+    List<Referrals> findByMedicalRecordRecordId(Long recordId);
+
+    // Find referrals created by a specific doctor (referrals from)
+    List<Referrals> findByFromDoctorDoctorId(Long doctorId);
+
+    // Find referrals sent to a specific doctor (referrals to)
+    List<Referrals> findByToDoctorDoctorId(Long doctorId);
+
+    // Helper: Get all referrals for a patient
+    @Query("""
+        SELECT r FROM Referrals r
+        WHERE r.medicalRecord.patient.patientId = :patientId
+        ORDER BY r.referralDate DESC
+    """)
+    List<Referrals> findReferralsForPatient(@Param("patientId") Long patientId);
+
+    // Helper: Get incoming referrals for a doctor
+    @Query("""
+        SELECT r FROM Referrals r
+        WHERE r.toDoctor.doctorId = :doctorId
+        ORDER BY r.referralDate DESC
+    """)
+    List<Referrals> findIncomingReferralsForDoctor(@Param("doctorId") Long doctorId);
+}
Index: backend/src/main/java/medora/repository/ReportAllergyRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ReportAllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ReportAllergyRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,13 @@
+package medora.repository;
+
+import medora.models.domain.ReportAllergy;
+import medora.models.domain.id.ReportAllergyId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ReportAllergyRepository extends JpaRepository<ReportAllergy, ReportAllergyId> {
+    List<ReportAllergy> findByReportReportId(Long reportId);
+}
Index: backend/src/main/java/medora/repository/ReportDiagnosisRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ReportDiagnosisRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ReportDiagnosisRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,13 @@
+package medora.repository;
+
+import medora.models.domain.ReportDiagnosis;
+import medora.models.domain.id.ReportDiagnosisId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ReportDiagnosisRepository extends JpaRepository<ReportDiagnosis, ReportDiagnosisId> {
+    List<ReportDiagnosis> findByReportReportId(Long reportId);
+}
Index: backend/src/main/java/medora/repository/ReportPrescriptionRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ReportPrescriptionRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ReportPrescriptionRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,13 @@
+package medora.repository;
+
+import medora.models.domain.ReportPrescription;
+import medora.models.domain.id.ReportPrescriptionId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ReportPrescriptionRepository extends JpaRepository<ReportPrescription, ReportPrescriptionId> {
+    List<ReportPrescription> findByReportReportId(Long reportId);
+}
Index: backend/src/main/java/medora/repository/ReportSymptomRepository.java
===================================================================
--- backend/src/main/java/medora/repository/ReportSymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/ReportSymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,13 @@
+package medora.repository;
+
+import medora.models.domain.ReportSymptom;
+import medora.models.domain.id.ReportSymptomId;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ReportSymptomRepository extends JpaRepository<ReportSymptom, ReportSymptomId> {
+    List<ReportSymptom> findByReportReportId(Long reportId);
+}
Index: backend/src/main/java/medora/repository/SymptomRepository.java
===================================================================
--- backend/src/main/java/medora/repository/SymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
+++ backend/src/main/java/medora/repository/SymptomRepository.java	(revision 98039727bade89604cb65116658c2bd917faa1fa)
@@ -0,0 +1,38 @@
+package medora.repository;
+
+
+import medora.models.domain.Symptoms;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import java.util.List;
+
+public interface SymptomRepository extends JpaRepository<Symptoms, Long> {
+//UC010 – Record Symptoms
+  //  A doctor records patient symptoms in the medical record.
+  //  Use save() method from JpaRepository
+
+    // Search symptoms by name
+            List<Symptoms> findByNameContainingIgnoreCase(String name);
+
+    // Helper: Get all symptoms for a patient's medical record
+    @Query("""
+        SELECT s FROM Symptoms s
+        WHERE s IN (
+            SELECT mrs.symptom FROM MedicalRecordSymptoms mrs
+            WHERE mrs.medicalRecord.recordId = :recordId
+        )
+    """)
+    List<Symptoms> findByMedicalRecordId(@Param("recordId") Long recordId);
+
+    // Helper: Get all symptoms for a patient
+    @Query("""
+        SELECT s FROM Symptoms s
+        WHERE s IN (
+            SELECT mrs.symptom FROM MedicalRecordSymptoms mrs
+            WHERE mrs.medicalRecord.patient.patientId = :patientId
+        )
+    """)
+    List<Symptoms> findByPatientId(@Param("patientId") Long patientId);
+}
