Skip to content

Conversation

@SauravBizbRolly
Copy link
Contributor

@SauravBizbRolly SauravBizbRolly commented Jan 7, 2026

📋 Description

JIRA ID:

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • Chores
    • Extended ANC visit records to include new optional fields: visit and LMP dates, sterilisation date, termination details and responsible party, place-of-care and place-of-death info, image attachments, serial/reference ID, yes/no flags, and free-text remarks.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Adds 20 new optional columns to the t_anc_visit table via a non-destructive migration (ADD COLUMN IF NOT EXISTS), introducing identifiers, text fields, timestamps, booleans, image paths, and location/remarks data for ANC records.

Changes

Cohort / File(s) Summary
Database Schema Migration
src/main/resources/db/migration/dbiemr/V37__DB_IEMR_anc_visit_column.sql
Adds ~20 columns to t_anc_visit: file_path, serial_no, method_of_termination, method_of_termination_id, termination_done_by, termination_done_by_id, is_paiucd_id, is_paiucd, remarks, abortion_img1, abortion_img2, place_of_death, place_of_death_id, other_place_of_death, visit_date, lmp_date, is_YesOrNo (boolean), date_of_sterilisation, place_of_anc, place_of_ancId; all added with IF NOT EXISTS.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hopped through rows and planted new fields bright, 🐇
Twenty soft columns to catch morning light,
Timestamps, images, and places now known,
Remarks and methods in tidy rows shown,
A little rabbit cheers the schema's new sight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'add new column in anc vist table' refers to the actual changes but contains a typo ('vist' instead of 'visit') and is overly generic, not specifying which columns were added or their purpose. Revise the title to be more specific and accurate, such as 'Add columns for pregnancy termination, sterilization, and place of ANC to anc_visit table' and fix the typo.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de97008 and 0c11b3b.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/dbiemr/V37__DB_IEMR_anc_visit_column.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/resources/db/migration/dbiemr/V37__DB_IEMR_anc_visit_column.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (java)
  • GitHub Check: Package-test

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

@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: 5

🤖 Fix all issues with AI agents
In @src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql:
- Around line 7-11: The migration adds method_of_termination_id and
termination_done_by_id but lacks foreign key constraints and indexes; update the
migration for table t_anc_visit to add FK constraints (e.g.,
fk_method_of_termination on method_of_termination_id referencing
m_method_of_termination(id) and fk_termination_done_by on termination_done_by_id
referencing m_termination_done_by(id)) and create indexes (e.g.,
idx_method_of_termination_id, idx_termination_done_by_id) on these columns; if
the varchar columns method_of_termination and termination_done_by are intended
as denormalized caches, add a comment in the migration or schema explaining that
decision.
- Around line 13-14: Reorder the two column additions so the textual column is
defined before its id (swap ADD COLUMN IF NOT EXISTS is_paiucd VARCHAR(10) and
ADD COLUMN IF NOT EXISTS is_paiucd_id INT) to match the ordering used for other
pairs; and clarify the design by either (a) renaming the text column to remove
the misleading "is_" prefix (e.g., paiucd or paiucd_value) if it is not a
boolean, or (b) converting it to a proper BOOLEAN type if the intent was a flag,
and keep the separate *_id only if you truly need an FK; also add a short inline
SQL comment or migration comment explaining what PAIUCD represents and why both
fields exist (referencing is_paiucd and is_paiucd_id).
- Around line 3-33: Migration ALTER TABLE t_anc_visit adds many new columns but
omits nullability, foreign keys, indexes, comments and sensible defaults; update
the migration to (1) set explicit NULL/NOT NULL for columns like visit_date,
lmp_date, remarks, is_YesOrNo and date_of_sterilisation per business rules, (2)
add foreign key constraints for method_of_termination_id,
termination_done_by_id, place_of_death_id, is_paiucd_id and place_of_ancId
referencing their lookup tables, (3) create indexes on those *_id columns (e.g.,
idx_method_of_termination_id), (4) add COMMENT clauses for ambiguous fields such
as file_path, serial_no, is_YesOrNo and abortion_img1/2 describing purpose, and
(5) apply sensible DEFAULTs where appropriate (e.g., default FALSE for
is_YesOrNo or CURRENT_TIMESTAMP for created/visit dates if required); locate
these changes around the ALTER TABLE t_anc_visit block and modify column
definitions and add separate ALTER TABLE ADD CONSTRAINT / ADD INDEX statements
as needed.
- Around line 32-33: The migration adds a column with inconsistent camelCase
naming: change the column name from place_of_ancId to snake_case
place_of_anc_id; update this migration SQL to use ADD COLUMN IF NOT EXISTS
place_of_anc_id INT (and ensure any subsequent references in the same migration
or related scripts—constraints, indexes, insert/select statements, foreign key
definitions—are updated from place_of_ancId to place_of_anc_id to maintain
naming consistency with other ID columns like method_of_termination_id and
place_of_death_id).
🧹 Nitpick comments (2)
src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql (2)

18-19: Consider a more flexible design for image storage.

Hard-coding support for exactly 2 abortion images (abortion_img1, abortion_img2) may be limiting. If more than 2 images might be needed in the future, consider:

  • Creating a separate t_anc_abortion_images table with a foreign key to t_anc_visit
  • Or document why exactly 2 images is a hard business requirement

3-6: Consider adding constraints and comments for consistency with recent migrations.

The columns lack explicit NULL/NOT EXISTS constraints and documentation comments. Recent migrations (V30, V31, V33) demonstrate the project standard of specifying constraints and defaults. For example:

  • Add NOT NULL or explicit DEFAULT NULL based on business requirements
  • Add COMMENT annotations to document column purpose (precedent: V17)

While the current code is functional, aligning with these conventions would improve maintainability and clarity.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2bb4f5 and ffb7401.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql (1)

1-2: LGTM: Database selection is appropriate.

The USE db_iemr; statement correctly targets the intended database for this migration.

Comment on lines 3 to 33
ALTER TABLE t_anc_visit
ADD COLUMN IF NOT EXISTS file_path VARCHAR(255),
ADD COLUMN IF NOT EXISTS serial_no VARCHAR(100),

ADD COLUMN IF NOT EXISTS method_of_termination VARCHAR(100),
ADD COLUMN IF NOT EXISTS method_of_termination_id INT,

ADD COLUMN IF NOT EXISTS termination_done_by VARCHAR(100),
ADD COLUMN IF NOT EXISTS termination_done_by_id INT,

ADD COLUMN IF NOT EXISTS is_paiucd_id INT,
ADD COLUMN IF NOT EXISTS is_paiucd VARCHAR(10),

ADD COLUMN IF NOT EXISTS remarks TEXT,

ADD COLUMN IF NOT EXISTS abortion_img1 VARCHAR(255),
ADD COLUMN IF NOT EXISTS abortion_img2 VARCHAR(255),

ADD COLUMN IF NOT EXISTS place_of_death VARCHAR(100),
ADD COLUMN IF NOT EXISTS place_of_death_id INT,
ADD COLUMN IF NOT EXISTS other_place_of_death VARCHAR(255),

ADD COLUMN IF NOT EXISTS visit_date TIMESTAMP,
ADD COLUMN IF NOT EXISTS lmp_date TIMESTAMP,

ADD COLUMN IF NOT EXISTS is_YesOrNo BOOLEAN,

ADD COLUMN IF NOT EXISTS date_of_sterilisation TIMESTAMP,

ADD COLUMN IF NOT EXISTS place_of_anc VARCHAR(100),
ADD COLUMN IF NOT EXISTS place_of_ancId INT;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add essential database constraints and documentation.

This migration lacks several essential elements for data integrity, performance, and maintainability:

  1. NULL constraints: No columns specify NULL or NOT NULL. Explicitly define nullability based on business requirements.
  2. Foreign key constraints: Multiple _id columns (method_of_termination_id, termination_done_by_id, place_of_death_id, is_paiucd_id, place_of_anc_id) likely reference lookup tables, but no FK constraints are defined.
  3. Indexes: Foreign key columns should have indexes for query performance.
  4. Column comments: Add COMMENT clauses to document the purpose of each field, especially for unclear names.
  5. Default values: Consider whether fields like is_YesOrNo (BOOLEAN) or timestamps should have default values.
🔎 Example: Adding constraints and documentation
-- Add NOT NULL constraints where appropriate (example)
ALTER TABLE t_anc_visit
  MODIFY COLUMN visit_date TIMESTAMP NOT NULL COMMENT 'Date of ANC visit',
  MODIFY COLUMN lmp_date TIMESTAMP COMMENT 'Last Menstrual Period date',
  MODIFY COLUMN remarks TEXT COMMENT 'Additional remarks for the visit';

-- Add foreign keys and indexes (adjust table names as appropriate)
ALTER TABLE t_anc_visit
  ADD CONSTRAINT fk_place_of_death 
    FOREIGN KEY (place_of_death_id) 
    REFERENCES m_place_of_death(id),
  ADD INDEX idx_place_of_death_id (place_of_death_id);
🤖 Prompt for AI Agents
In @src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql
around lines 3 - 33, Migration ALTER TABLE t_anc_visit adds many new columns but
omits nullability, foreign keys, indexes, comments and sensible defaults; update
the migration to (1) set explicit NULL/NOT NULL for columns like visit_date,
lmp_date, remarks, is_YesOrNo and date_of_sterilisation per business rules, (2)
add foreign key constraints for method_of_termination_id,
termination_done_by_id, place_of_death_id, is_paiucd_id and place_of_ancId
referencing their lookup tables, (3) create indexes on those *_id columns (e.g.,
idx_method_of_termination_id), (4) add COMMENT clauses for ambiguous fields such
as file_path, serial_no, is_YesOrNo and abortion_img1/2 describing purpose, and
(5) apply sensible DEFAULTs where appropriate (e.g., default FALSE for
is_YesOrNo or CURRENT_TIMESTAMP for created/visit dates if required); locate
these changes around the ALTER TABLE t_anc_visit block and modify column
definitions and add separate ALTER TABLE ADD CONSTRAINT / ADD INDEX statements
as needed.

Comment on lines 7 to 11
ADD COLUMN IF NOT EXISTS method_of_termination VARCHAR(100),
ADD COLUMN IF NOT EXISTS method_of_termination_id INT,

ADD COLUMN IF NOT EXISTS termination_done_by VARCHAR(100),
ADD COLUMN IF NOT EXISTS termination_done_by_id INT,
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add foreign key constraints for referential integrity.

The method_of_termination_id and termination_done_by_id fields appear to reference lookup tables, but no foreign key constraints are defined. This risks data integrity issues.

Consider:

  • Adding FK constraints to the referenced tables
  • Adding indexes on these foreign key columns for query performance
  • If the text fields (method_of_termination, termination_done_by) are meant to cache values from the referenced tables, document this denormalization decision
🔎 Example: Adding FK constraints and indexes
-- After adding columns, add constraints (adjust table names as appropriate):
ALTER TABLE t_anc_visit
  ADD CONSTRAINT fk_method_of_termination 
    FOREIGN KEY (method_of_termination_id) 
    REFERENCES m_method_of_termination(id),
  ADD CONSTRAINT fk_termination_done_by 
    FOREIGN KEY (termination_done_by_id) 
    REFERENCES m_termination_done_by(id),
  ADD INDEX idx_method_of_termination_id (method_of_termination_id),
  ADD INDEX idx_termination_done_by_id (termination_done_by_id);
🤖 Prompt for AI Agents
In @src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql
around lines 7 - 11, The migration adds method_of_termination_id and
termination_done_by_id but lacks foreign key constraints and indexes; update the
migration for table t_anc_visit to add FK constraints (e.g.,
fk_method_of_termination on method_of_termination_id referencing
m_method_of_termination(id) and fk_termination_done_by on termination_done_by_id
referencing m_termination_done_by(id)) and create indexes (e.g.,
idx_method_of_termination_id, idx_termination_done_by_id) on these columns; if
the varchar columns method_of_termination and termination_done_by are intended
as denormalized caches, add a comment in the migration or schema explaining that
decision.

Comment on lines 13 to 14
ADD COLUMN IF NOT EXISTS is_paiucd_id INT,
ADD COLUMN IF NOT EXISTS is_paiucd VARCHAR(10),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent ordering and unclear design pattern.

Two issues here:

  1. Ordering inconsistency: is_paiucd_id appears before is_paiucd, while other similar fields in this migration place the text column before the ID column (lines 7-8, 10-11, 21-22, 32-33).
  2. Unclear design: The is_ prefix suggests a boolean flag, yet is_paiucd is VARCHAR(10) with a separate _id field. This pattern is confusing and should be clarified or redesigned.

Consider reordering for consistency and documenting what PAIUCD represents and why it needs both a text field and an ID field.

🤖 Prompt for AI Agents
In @src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql
around lines 13 - 14, Reorder the two column additions so the textual column is
defined before its id (swap ADD COLUMN IF NOT EXISTS is_paiucd VARCHAR(10) and
ADD COLUMN IF NOT EXISTS is_paiucd_id INT) to match the ordering used for other
pairs; and clarify the design by either (a) renaming the text column to remove
the misleading "is_" prefix (e.g., paiucd or paiucd_value) if it is not a
boolean, or (b) converting it to a proper BOOLEAN type if the intent was a flag,
and keep the separate *_id only if you truly need an FK; also add a short inline
SQL comment or migration comment explaining what PAIUCD represents and why both
fields exist (referencing is_paiucd and is_paiucd_id).

ADD COLUMN IF NOT EXISTS visit_date TIMESTAMP,
ADD COLUMN IF NOT EXISTS lmp_date TIMESTAMP,

ADD COLUMN IF NOT EXISTS is_YesOrNo BOOLEAN,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Replace generic field name with a descriptive one.

The column name is_YesOrNo is extremely vague and provides no indication of what it represents in the context of an ANC visit. This severely impacts code maintainability and readability.

Replace with a descriptive name that clearly indicates the field's purpose, such as is_high_risk_pregnancy, is_consent_given, or whatever the actual business meaning is.

Comment on lines 32 to 33
ADD COLUMN IF NOT EXISTS place_of_anc VARCHAR(100),
ADD COLUMN IF NOT EXISTS place_of_ancId INT;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix critical naming convention inconsistency.

The column place_of_ancId uses camelCase (ancId), which is inconsistent with all other ID columns in this migration that use snake_case (method_of_termination_id, termination_done_by_id, place_of_death_id, is_paiucd_id).

This inconsistency will cause confusion and potential bugs. Database column names should follow a consistent naming convention.

🔎 Proposed fix
 ADD COLUMN IF NOT EXISTS place_of_anc VARCHAR(100),
-ADD COLUMN IF NOT EXISTS place_of_ancId INT;
+ADD COLUMN IF NOT EXISTS place_of_anc_id INT;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ADD COLUMN IF NOT EXISTS place_of_anc VARCHAR(100),
ADD COLUMN IF NOT EXISTS place_of_ancId INT;
ADD COLUMN IF NOT EXISTS place_of_anc VARCHAR(100),
ADD COLUMN IF NOT EXISTS place_of_anc_id INT;
🤖 Prompt for AI Agents
In @src/main/resources/db/migration/dbiemr/V34__DB_IEMR_anc_visit_column.sql
around lines 32 - 33, The migration adds a column with inconsistent camelCase
naming: change the column name from place_of_ancId to snake_case
place_of_anc_id; update this migration SQL to use ADD COLUMN IF NOT EXISTS
place_of_anc_id INT (and ensure any subsequent references in the same migration
or related scripts—constraints, indexes, insert/select statements, foreign key
definitions—are updated from place_of_ancId to place_of_anc_id to maintain
naming consistency with other ID columns like method_of_termination_id and
place_of_death_id).

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 8, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants