Skip to content

Feat/medical record dto request#32

Open
annikaholmqvist94 wants to merge 5 commits intomainfrom
feat/Medical-record-dto-request
Open

Feat/medical record dto request#32
annikaholmqvist94 wants to merge 5 commits intomainfrom
feat/Medical-record-dto-request

Conversation

@annikaholmqvist94
Copy link
Copy Markdown
Contributor

@annikaholmqvist94 annikaholmqvist94 commented Mar 27, 2026

Enabled jakarta validation, Created Packages for request and response DTOs for data transfer.

(Verkar som comment entity commiten råkade komma med här också haha ops)

Summary by CodeRabbit

  • New Features

    • Added commenting on medical records with author and timestamps
    • Enabled assigning veterinarians to records
    • Added detailed and summary medical record views showing pet, owner, clinic, and assigned vet
  • Bug Fixes / Improvements

    • Enforced validation on create/update/assign/status requests with clear messages and field limits

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Warning

Rate limit exceeded

@annikaholmqvist94 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 50 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 50 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf3a92d4-cc4c-4ba7-843b-84ff79b64689

📥 Commits

Reviewing files that changed from the base of the PR and between 6161c49 and bfa792e.

📒 Files selected for processing (2)
  • src/main/java/org/example/vet1177/repository/MedicalRecordRepository.java
  • src/main/java/org/example/vet1177/services/MedicalRecordService.java
📝 Walkthrough

Walkthrough

Adds Jakarta Bean Validation dependency and introduces new medical-record request/response DTOs, a Comment JPA entity, CommentRepository, and EntityGraph-driven eager fetch updates on MedicalRecordRepository.

Changes

Cohort / File(s) Summary
Dependency
pom.xml
Added org.springframework.boot:spring-boot-starter-validation to enable bean validation at runtime.
Request DTOs
src/main/java/org/example/vet1177/dto/request/medicalrecord/AssignVetRequest.java, src/main/java/org/example/vet1177/dto/request/medicalrecord/CreateMedicalRecordRequest.java, src/main/java/org/example/vet1177/dto/request/medicalrecord/UpdateMedicalRecordRequest.java, src/main/java/org/example/vet1177/dto/request/medicalrecord/UpdateStatusRequest.java
Added four request records with Jakarta Bean Validation annotations (e.g., @NotNull, @NotBlank, @Size) and Swedish validation messages.
Response DTOs
src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordResponse.java, src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordSummaryResponse.java
Added two response records with static from(...) factory methods mapping MedicalRecord entity to DTOs (detailed and summary forms).
Comment entity & repository
src/main/java/org/example/vet1177/entities/Comment.java, src/main/java/org/example/vet1177/repository/CommentRepository.java
Introduced Comment JPA entity (UUID id, relations to MedicalRecord and User, body, timestamps, lifecycle callbacks) and CommentRepository with derived query methods (by record, by author, count by record).
MedicalRecordRepository updates
src/main/java/org/example/vet1177/repository/MedicalRecordRepository.java
Added/updated @EntityGraph annotations to several query methods and explicitly declared Optional<MedicalRecord> findById(UUID id) with eager fetch paths for related entities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

infrastruktur

Suggested reviewers

  • johanbriger
  • lindaeskilsson
  • TatjanaTrajkovic

Poem

🐇 I hop in code with cheerful cheer,
Validation snug and DTOs near,
Comments nestle, timestamps clear,
Records linked — the path is dear,
Spring blossoms — a rabbit's tiny cheer 🌷

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Feat/medical record dto request' directly describes the primary changes: creation of request DTOs for medical records and integration of validation support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/Medical-record-dto-request

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/java/org/example/vet1177/repository/CommentRepository.java (1)

17-17: Add an index for findByAuthorId to avoid table scans at scale.

findByAuthorId(UUID authorId) introduces a likely hot lookup path, but current DDL only indexes (record_id, created_at) (src/main/resources/schema.sql:98). Add an index on author_id.

📈 Suggested schema addition
+CREATE INDEX IF NOT EXISTS idx_comment_author ON comment(author_id);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/vet1177/repository/CommentRepository.java` at line
17, The repository method findByAuthorId(UUID authorId) will cause table scans
at scale because there is no index on the author_id column; add a dedicated
index on author_id for the comments table (e.g., CREATE INDEX
idx_comments_author_id ON comments (author_id)) in your DDL/migration (use
CREATE INDEX CONCURRENTLY for Postgres in production migrations), and give the
index a clear name so the findByAuthorId path uses it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordResponse.java`:
- Around line 30-49: MedicalRecordResponse.from(...) dereferences LAZY
associations on MedicalRecord (pet, owner, clinic, assignedVet, createdBy) and
will throw LazyInitializationException when called outside a transaction; fix by
ensuring DTO mapping happens while the entity is attached — either perform the
conversion inside a `@Transactional` service method (map to MedicalRecordResponse
in the service rather than in controllers) or change the repository query that
loads MedicalRecord to eagerly fetch required associations (use `@EntityGraph` or
a JPQL/Criteria query with JOIN FETCH for pet, owner, clinic, assignedVet,
createdBy) so that MedicalRecordResponse.from(...) can safely access those
fields.

In `@src/main/java/org/example/vet1177/entities/Comment.java`:
- Line 58: The public setter setUpdatedAt in class Comment allows external
mutation of the audit field updatedAt; remove the public setter or change its
visibility to private/protected so updatedAt is only modified by the entity
lifecycle (e.g., JPA `@PreUpdate/`@PrePersist methods or the repository/service
layer), and ensure any lifecycle hook or method (e.g., a private
updateTimestamps or existing `@PreUpdate/`@PrePersist) is used to set updatedAt
instead of external callers.

---

Nitpick comments:
In `@src/main/java/org/example/vet1177/repository/CommentRepository.java`:
- Line 17: The repository method findByAuthorId(UUID authorId) will cause table
scans at scale because there is no index on the author_id column; add a
dedicated index on author_id for the comments table (e.g., CREATE INDEX
idx_comments_author_id ON comments (author_id)) in your DDL/migration (use
CREATE INDEX CONCURRENTLY for Postgres in production migrations), and give the
index a clear name so the findByAuthorId path uses it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98c1fa92-cacf-4159-85d4-71dd785430d7

📥 Commits

Reviewing files that changed from the base of the PR and between 028da4c and 5ea38d1.

📒 Files selected for processing (9)
  • pom.xml
  • src/main/java/org/example/vet1177/dto/request/medicalrecord/AssignVetRequest.java
  • src/main/java/org/example/vet1177/dto/request/medicalrecord/CreateMedicalRecordRequest.java
  • src/main/java/org/example/vet1177/dto/request/medicalrecord/UpdateMedicalRecordRequest.java
  • src/main/java/org/example/vet1177/dto/request/medicalrecord/UpdateStatusRequest.java
  • src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordResponse.java
  • src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordSummaryResponse.java
  • src/main/java/org/example/vet1177/entities/Comment.java
  • src/main/java/org/example/vet1177/repository/CommentRepository.java

- Applied `@EntityGraph` to relevant repository methods for fetching associated entities.
- Added `findById` method with `@EntityGraph`.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/example/vet1177/repository/MedicalRecordRepository.java`:
- Around line 21-31: The `@EntityGraph` on the repository query methods
findByPetId, findByOwnerId, findByClinicId and findByClinicIdAndStatus omits the
"createdBy" association causing LazyInitializationException when
MedicalRecordResponse.from() accesses record.getCreatedBy(); update each
`@EntityGraph` attributePaths to include "createdBy" alongside
"pet","owner","clinic","assignedVet" so the createdBy relationship is eagerly
fetched.
- Around line 33-34: The repository methods findByAssignedVetId and findByStatus
in MedicalRecordRepository are missing the `@EntityGraph` used by the other
finders and will cause LazyInitializationException when results are mapped by
MedicalRecordResponse.from()/MedicalRecordSummaryResponse.from(); fix by adding
`@EntityGraph`(attributePaths = {"pet","owner","clinic","assignedVet"}) above both
findByAssignedVetId(UUID vetId) and findByStatus(RecordStatus status) to eagerly
fetch those associations (or, if these methods are truly unused, remove them
from MedicalRecordRepository to avoid exposing a broken API).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 381bd2e9-13cb-4eb8-901e-3ded03c41a58

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea38d1 and 6161c49.

📒 Files selected for processing (2)
  • src/main/java/org/example/vet1177/entities/Comment.java
  • src/main/java/org/example/vet1177/repository/MedicalRecordRepository.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/example/vet1177/entities/Comment.java

Comment on lines +33 to +34
List<MedicalRecord> findByAssignedVetId(UUID vetId);
List<MedicalRecord> findByStatus(RecordStatus status);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for usages of findByAssignedVetId and findByStatus to determine if they need `@EntityGraph`

echo "=== Usages of findByAssignedVetId ==="
rg -n -C5 'findByAssignedVetId' --type java

echo ""
echo "=== Usages of findByStatus ==="
rg -n -C5 'findByStatus' --type java -g '!*Repository*'

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 1110


🏁 Script executed:

# Search for usages of these methods in all files including tests and other locations
echo "=== All usages of findByAssignedVetId (expanded search) ==="
rg 'findByAssignedVetId' -n --type-list | head -20

echo ""
echo "=== All usages of findByStatus (expanded search) ==="
rg 'findByStatus' -n --type-list | head -20

echo ""
echo "=== Check MedicalRecord entity and response classes ==="
find . -name "*MedicalRecord*" -type f | head -20

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 1641


🏁 Script executed:

# Look for the response converter classes mentioned in the review
rg 'MedicalRecordResponse|MedicalRecordSummaryResponse' -l --type java

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 270


🏁 Script executed:

# Check the MedicalRecord entity definition to understand lazy associations
rg -A30 'class MedicalRecord' --type java

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 5938


🏁 Script executed:

# Examine the response converter classes
cat src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordResponse.java

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 1805


🏁 Script executed:

# Examine the summary response converter
cat src/main/java/org/example/vet1177/dto/response/medicalrecord/MedicalRecordSummaryResponse.java

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 1024


🏁 Script executed:

# Check the MedicalRecordService to see which repository methods are actually called
rg 'medicalRecordRepository\.' src/main/java/org/example/vet1177/services/MedicalRecordService.java -A2

Repository: ithsjava25/project-backend-org-random-coders

Length of output: 859


findByAssignedVetId and findByStatus are either unused or need @EntityGraph for consistency.

These methods currently have no usages in the codebase, but if they are intended as public API and used with MedicalRecordResponse.from() or MedicalRecordSummaryResponse.from(), they will cause LazyInitializationException when accessing lazy associations (pet, owner, clinic, assignedVet). All other finder methods (findByPetId, findByOwnerId, findByClinicId, findByClinicIdAndStatus) already have @EntityGraph annotations.

Either remove these methods as unused API, or add the appropriate @EntityGraph annotation (e.g., @EntityGraph(attributePaths = {"pet", "owner", "clinic", "assignedVet"})) for consistency with the other finders.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/vet1177/repository/MedicalRecordRepository.java`
around lines 33 - 34, The repository methods findByAssignedVetId and
findByStatus in MedicalRecordRepository are missing the `@EntityGraph` used by the
other finders and will cause LazyInitializationException when results are mapped
by MedicalRecordResponse.from()/MedicalRecordSummaryResponse.from(); fix by
adding `@EntityGraph`(attributePaths = {"pet","owner","clinic","assignedVet"})
above both findByAssignedVetId(UUID vetId) and findByStatus(RecordStatus status)
to eagerly fetch those associations (or, if these methods are truly unused,
remove them from MedicalRecordRepository to avoid exposing a broken API).

- Extended `@EntityGraph` with `createdBy` for detailed entity fetching.
- Replaced runtime exceptions with specific exceptions (`BusinessRuleException`, `ResourceNotFoundException`).
- Prevent updates to finalized records with additional business rule validation.
- Improved error handling for record closing logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant