Skip to content

Conversation

leite08
Copy link
Member

@leite08 leite08 commented Mar 6, 2025

Ticket: https://github.com/metriport/metriport-internal/issues/2330

Dependencies

Description

  • refactor the state management of patient bulk import
    • add DB table to store and calculate the state of bulk import
    • on S3, store CSV records, and a mapping to the patient IDs
  • revamp the internal endpoints for bulk import
  • upon data pipeline completion, check/finish the bulk import
  • send WH at the start and end of bulk import

Testing

  • Local
    • Create bulk import
    • "Continue"/resume bulk import (manually, as on the cloud it'll be automatically triggered by a lambda)
    • Get info about bulk import state
    • Patients get mapped to their records on the DB
    • Upon start, receive WH request w/ processing status
    • Upon completion, receive WH request w/ completed status and link to download result.csv file
  • Local branch to staging
    • Create bulk import from public endpoint runs it automatically
    • Create bulk import from internal endpoint runs it automatically
    • "Continue" endpoint `w/ 'force" runs it again
    • Get info about bulk import state
    • Patients get mapped to their records on the DB
    • Upon start, receive WH request w/ processing status
    • Upon completion, receive WH request w/ completed status and link to download result.csv file
  • Staging
    • Create bulk import from public endpoint w/o dry-run runs it automatically
    • Create bulk import from public endpoint w/ dry-run just dry runs
    • "Continue" endpoint `w/ 'force" runs it again
    • Get info about bulk import state
    • Patients get mapped to their records on the DB
    • Upon start, receive WH request w/ processing status
    • Upon completion, receive WH request w/ completed status and link to download result.csv file
    • Create bulk import from internal endpoint runs it automatically
  • Sandbox
    • none
  • Production
    • none

Release Plan

  • ⚠️ This contains a DB migration
  • Release NPM packages
  • Merge this

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive bulk patient import system with full lifecycle API endpoints for job creation, continuation, completion, status updates, and patient mapping.
    • Added new webhook support for bulk patient import statuses, including presigned URLs for result file downloads.
    • Implemented detailed job status tracking, patient record management, and error reporting mechanisms.
    • Added AWS Lambda handlers and infrastructure support for patient import parsing, querying, creation, and result processing.
  • Improvements

    • Enhanced CSV parsing, validation, and normalization with improved handling of address fields and patient data.
    • Improved logging, error monitoring, and Sentry integration across import-related lambdas and API routes.
    • Refined API schemas and DTOs for patient import workflows.
    • Refactored code to centralize error handling and improve concurrency management during import processing.
  • Bug Fixes

    • Fixed CSV normalization issues and improved robustness for diverse CSV header formats.
    • Corrected documentation comments and improved consistency in webhook message descriptions.
  • Chores

    • Added database migrations for patient import job and mapping tables with triggers and constraints.
    • Updated package versions and dependencies, including shared utilities and SDKs.
    • Refactored codebase to delegate domain and utility types to shared packages.
    • Removed deprecated code and consolidated UUID utilities to shared modules.
  • Tests

    • Added extensive unit and integration tests covering patient import logic, address parsing, status validation, concurrency utilities, and error handling.
  • Documentation

    • Updated API documentation and internal docs for bulk patient import endpoints, webhook message formats, and usage notes.

Copy link

coderabbitai bot commented Mar 6, 2025

Walkthrough

This update introduces a comprehensive redesign and expansion of the bulk patient import feature across the system. It adds new database tables and models for tracking bulk import jobs and patient mappings, implements robust S3 storage and retrieval utilities, and refactors the entire import pipeline to support concurrency-safe status updates, granular error handling, and flexible dry-run operations. The API, Lambda handlers, and CLI utilities are updated to use new domain types, schemas, and endpoint structures. Webhook support is extended to cover bulk imports, and new endpoints and internal routes are provided for job lifecycle management. Supporting libraries and shared utilities are enhanced with new types, error handling, and configuration mechanisms. Numerous tests, documentation updates, and infrastructure changes accompany the core logic revisions.

Changes

Files/Paths Change Summary
API Models, Migrations, and Config
.../models/medical/patient-import.ts, .../models/medical/patient-import-mapping.ts Added Sequelize models for patient import jobs and mappings.
.../sequelize/migrations/2025-04-28_00_create-patient_import-table.ts, .../2025-04-28_01_alter-patient_import-add-change-log.ts, .../2025-04-28_02_create-patient_import_mapping-table.ts Added migrations for new tables and triggers for patient import jobs and mappings.
.../models/db.ts Registered new models in Sequelize initialization.
.../.env.test Added PATIENT_IMPORT_BUCKET_NAME variable.
API Command & Route Logic
.../command/medical/patient/patient-import/create.ts, .../command/medical/patient/patient-import/finish-job.ts, .../command/medical/patient/patient-import/finish-single-patient.ts, .../command/medical/patient/patient-import/get.ts, .../command/medical/patient/patient-import/get-mapping-and-import.ts, .../command/medical/patient/patient-import/mapping/create.ts, .../command/medical/patient/patient-import/mapping/get.ts, .../command/medical/patient/patient-import/process-patient-import-webhook.ts, .../command/medical/patient/patient-import/store-entry-status.ts, .../command/medical/patient/patient-import/update-params.ts, .../command/medical/patient/patient-import/update-tracking.ts Added/rewrote modules for creating, updating, finishing, and mapping patient import jobs, including concurrency-safe tracking and S3 integration.
.../command/medical/patient/patient-import-create-job.ts Deleted legacy job creation logic, replaced by new modules.
.../routes/internal/medical/patient-import.ts New router for internal bulk patient import job management (create, continue, complete, update, retrieve, mapping).
.../routes/internal/medical/patient.ts Refactored to mount new bulk router and update endpoints for modern import flow.
.../routes/medical/dtos/patient-import.ts Updated DTOs for new job response structure, added conversion helper.
.../routes/medical/patient-root.ts Updated /patient/bulk endpoint to use new job creation logic and DTOs.
API Webhook, Error Handling, and Logging
.../command/medical/document/document-webhook.ts, .../command/medical/document/process-doc-query-webhook.ts Refactored webhook metadata handling and patient import job finalization calls.
.../routes/helpers/default-error-handler.ts, .../app.ts Improved error capture, logging, and Sentry integration.
Core Patient Import Pipeline
.../core/src/command/patient-import/api/ Added/updated API utilities for patient mapping, patient creation, document/patient query, and job status update with improved error handling.
.../core/src/command/patient-import/csv/ Refactored CSV parsing, normalization, result storage, and validation with new types and error handling; added helpers for escaping CSV and checking S3 results.
.../core/src/command/patient-import/patient-import-shared.ts Overhauled S3 key generation and file structure logic for jobs, patients, and mappings.
.../core/src/command/patient-import/patient-import.ts Redefined types for job records, patient records, and parsing results; added type guards.
.../core/src/command/patient-import/record/ Refactored record creation, update, fetch, and listing for jobs and patients; added shared serialization helper.
.../core/src/command/patient-import/steps/ Refactored step handler interfaces and implementations for create, parse, query, and result; improved error handling, concurrency, and dry-run logic.
.../core/src/command/patient-import/api/shared.ts Added a utility for standardized API error handling.
.../core/src/domain/base-domain.ts Now re-exports base domain interfaces from shared module.
.../core/src/mpi/normalize-patient.ts Minor error return value change for clarity.
.../core/src/util/config.ts Added/renamed config getters for Lambda function names.
.../core/src/util/uuid-v7.ts Now re-exports UUIDv7 utilities from shared module.
Shared Domain, Types, and Utilities
.../shared/src/domain/base-domain.ts Added base domain entity interfaces.
.../shared/src/domain/patient/patient-import/ Added/updated types, status logic, mapping interfaces, schemas, metadata helpers, and dry-run logic for patient import jobs.
.../shared/src/medical/webhook/webhook-request.ts Added bulk patient import webhook types, schemas, and type guards.
.../shared/src/common/numbers.ts Added randomIntBetween utility.
.../shared/src/util/uuid-v7.ts Added full UUIDv7 implementation.
.../shared/src/index.ts Now exports only patient import schemas.
AWS, Infra, and Lambda
.../infra/lib/api-stack.ts, .../infra/lib/api-stack/api-service.ts, .../infra/lib/patient-import-nested-stack.ts Updated to deploy and wire up separate parse/result Lambda functions for patient import, with proper permissions and environment variables.
.../lambdas/src/patient-import-create.ts, .../lambdas/src/patient-import-parse.ts, .../lambdas/src/patient-import-query.ts, .../lambdas/src/patient-import-result.ts, .../lambdas/src/patient-import-upload-notification.ts Refactored Lambda handlers for new types, Sentry integration, improved error handling, and new job/patient record logic.
.../lambdas/src/shared/file-info.ts Marked S3 file info utility as deprecated in favor of new S3Utils.
Documentation and Examples
docs/medical-api/ Updated and clarified bulk patient import and webhook documentation.
samples/typescript-express/ Updated dependencies, scripts, and webhook handler to support new bulk import webhook types and type guards.
Tests
.../__tests__/ Added and updated tests for address parsing, patient import status logic, dry-run detection, CSV validation, and random number utility.
Miscellaneous
packages/api-sdk/package.json, packages/core/package.json, packages/shared/package.json, packages/infra/package.json, packages/utils/package.json, packages/commonwell-sdk/package.json, packages/commonwell-cert-runner/package.json, packages/commonwell-jwt-maker/package.json, packages/carequality-cert-runner/package.json, packages/carequality-sdk/package.json, packages/ihe-gateway-sdk/package.json, samples/typescript-express/package.json Bumped package versions and updated dependencies as needed.
packages/utils/src/mock-webhook.ts Deleted mock webhook server (moved to sample or replaced).
packages/utils/src/patient-import/send-webhook.ts Added standalone script for sending bulk import webhook payloads.
packages/utils/src/patient-import/generate-patient-csv.ts, packages/utils/src/patient-import/validate-file.ts, packages/utils/src/patient-import/shared.ts Updated to use new patient import types and improved validation/output logic.
packages/utils/tsconfig.json, samples/typescript-express/tsconfig.json Added/updated TypeScript config for stricter checks and script support.

Sequence Diagram(s)

Bulk Patient Import Job Lifecycle

sequenceDiagram
    participant Client
    participant API
    participant DB
    participant S3
    participant LambdaParse
    participant LambdaResult
    participant Webhook

    Client->>API: POST /patient/bulk (create job)
    API->>DB: Insert patient_import job
    API->>S3: Create job record & presigned upload URL
    API-->>Client: Return job info + upload URL

    Client->>S3: Upload CSV via presigned URL

    S3-->>LambdaParse: S3 event triggers parse Lambda

    LambdaParse->>S3: Read uploaded CSV
    LambdaParse->>API: Update job status to 'processing'
    LambdaParse->>S3: Store parsed patient records
    LambdaParse->>API: Update job status, counters

    alt Dry run
        LambdaParse->>LambdaResult: Trigger result Lambda (dry run)
    else Not dry run
        LambdaParse->>API: For each patient, create & map
        API->>S3: Update patient record status
        API->>API: Update job counters
        API->>LambdaResult: Trigger result Lambda when done
    end

    LambdaResult->>S3: Consolidate results, store result CSV
    LambdaResult->>API: Update job status to 'completed'
    LambdaResult->>Webhook: Send bulk patient import webhook (with result URL)
Loading

Bulk Patient Import Webhook Flow

sequenceDiagram
    participant API
    participant Webhook
    participant S3

    API->>S3: Generate presigned URL for result CSV
    API->>Webhook: POST webhook with jobId, status, result URL
    Webhook-->>API: 200 OK
Loading

Patient Record Status Update (Concurrency-Safe)

sequenceDiagram
    participant Lambda
    participant API
    participant DB

    Lambda->>API: Update patient entry status (successful/failed)
    API->>DB: Atomic increment of counters
    API->>DB: Fetch updated job status
    API-->>Lambda: Return updated counters/status
Loading

Note: Additional diagrams could be produced for mapping creation, error flows, or detailed S3 interactions if needed.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@leite08 leite08 force-pushed the 2330-bulk-import-db branch 3 times, most recently from 0bc2b63 to 86774f6 Compare March 21, 2025 23:19
@leite08 leite08 force-pushed the 2330-bulk-import-db branch 3 times, most recently from 095480c to 5d38778 Compare March 25, 2025 20:29
@leite08 leite08 changed the base branch from develop to 2330-store-pt-creates March 27, 2025 00:16
@leite08 leite08 force-pushed the 2330-bulk-import-db branch 2 times, most recently from 8f2411a to bd37d95 Compare March 27, 2025 01:35
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to packages/shared/src/domain/patient/patient-import/schemas.ts

leite08 added 2 commits April 28, 2025 13:47
Ref. metriport/metriport-internal#2330

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Ref. metriport/metriport-internal#2330

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Base automatically changed from 2330-store-pt-creates to develop April 28, 2025 16:50
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: 0

🧹 Nitpick comments (10)
packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts (2)

11-13: Comment should be more descriptive.

The comment "Use 'Promise.all' when changes are independent of each other" doesn't match what the code is actually doing. This migration is using sequential operations within a transaction, not parallel Promise.all execution.

-// Use 'Promise.all' when changes are independent of each other
+// Create patient import mapping table to associate patient records with bulk import jobs

51-57: Use dynamic constraint name from PostgreSQL.

Rather than hardcoding the constraint name, let PostgreSQL dynamically generate it to avoid potential naming conflicts when the migration is applied to different environments.

-    await queryInterface.addConstraint(tableName, {
-      name: constraintName,
-      fields: constraintFieldNames,
-      type: "unique",
-      transaction,
-    });
+    await queryInterface.addConstraint(tableName, {
+      fields: constraintFieldNames,
+      type: "unique",
+      transaction,
+    });
packages/api/src/sequelize/migrations/2025-04-28_01_alter-patient_import-add-change-log.ts (3)

15-16: Comment doesn't match implementation.

The comment suggests using Promise.all for independent changes, but the implementation doesn't use Promise.all since there's only a single operation.

-// Use 'Promise.all' when changes are independent of each other
+// Add change logging trigger to patient_import table

16-20: Consider validating trigger existence before creation.

The migration could fail if the trigger already exists. Consider adding a condition to check if the trigger already exists before trying to create it.

export const up: Migration = async ({ context: queryInterface }) => {
  await queryInterface.sequelize.transaction(async transaction => {
+    // Check if trigger exists first
+    const [results] = await queryInterface.sequelize.query(
+      `SELECT 1 FROM pg_trigger WHERE tgname = '${triggerName}'`,
+      { transaction }
+    );
+    if ((results as any[]).length === 0) {
      await queryInterface.sequelize.query(getChangeTriggerCreateCmd(), { transaction });
+    }
  });
};

22-26: Consider using a transaction-aware query for down migration.

For consistency with the approach in up, consider using the raw query approach with sequelize.query instead of the dropTrigger method, as this ensures consistent transaction handling.

export const down: Migration = ({ context: queryInterface }) => {
  return queryInterface.sequelize.transaction(async transaction => {
-    await queryInterface.dropTrigger(tableName, triggerName, { transaction });
+    await queryInterface.sequelize.query(
+      `DROP TRIGGER IF EXISTS ${triggerName} ON ${tableName}`,
+      { transaction }
+    );
  });
};
packages/api/src/sequelize/migrations/2025-04-28_00_create-patient_import-table.ts (5)

7-8: Comment doesn't match implementation.

The comment suggests using Promise.all for independent changes, but the implementation doesn't use Promise.all since there's only a single createTable operation.

-// Use 'Promise.all' when changes are independent of each other
+// Create patient_import table to store bulk import job status and metadata

33-36: Consider adding length limit to reason field.

The reason field is defined as a string without length constraints. Consider adding a maximum length to prevent excessively large values.

reason: {
  type: DataTypes.STRING,
+  // Specify reasonable length limit for error messages
+  type: DataTypes.STRING(1024),
  allowNull: true,
},

47-61: Add comments explaining counter fields.

The counter fields (total, successful, failed) would benefit from brief comments explaining their purpose in the context of patient imports.

total: {
  type: DataTypes.INTEGER,
  allowNull: false,
  defaultValue: 0,
+  // Total number of patient records in the import job
},
successful: {
  type: DataTypes.INTEGER,
  allowNull: false,
  defaultValue: 0,
+  // Count of successfully imported patient records
},
failed: {
  type: DataTypes.INTEGER,
  allowNull: false,
  defaultValue: 0,
+  // Count of failed patient record imports
},

62-71: Consider adding JSONB validation or schema documentation.

The JSONB fields paramsCx and paramsOps don't have any documentation about their expected structure. Consider adding comments documenting the expected schema.

paramsCx: {
  type: DataTypes.JSONB,
  field: "params_cx",
  allowNull: false,
+  // Customer-specific parameters for the import job
+  // Expected schema: { ... }
},
paramsOps: {
  type: DataTypes.JSONB,
  field: "params_ops",
  allowNull: false,
+  // Operational parameters for the import job
+  // Expected schema: { ... }
},

13-72: Consider adding indexes for frequent query patterns.

The table might benefit from additional indexes on frequently queried columns like cx_id, facility_id, or status to improve query performance, especially for listing/filtering operations.

// After creating the table
await shared.createTable(
  // ... existing code
);
+// Add indexes for frequently queried columns
+await queryInterface.addIndex(jobTableName, {
+  fields: ["cx_id"],
+  transaction,
+});
+await queryInterface.addIndex(jobTableName, {
+  fields: ["facility_id"],
+  transaction,
+});
+await queryInterface.addIndex(jobTableName, {
+  fields: ["status"],
+  transaction,
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc0edb and f3ae151.

📒 Files selected for processing (3)
  • packages/api/src/sequelize/migrations/2025-04-28_00_create-patient_import-table.ts (1 hunks)
  • packages/api/src/sequelize/migrations/2025-04-28_01_alter-patient_import-add-change-log.ts (1 hunks)
  • packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - Try to use immutable code and avoid sharing state across different functions, objects, and systems - Try...

**/*.ts: - Use the Onion Pattern to organize a package's code in layers

  • Try to use immutable code and avoid sharing state across different functions, objects, and systems
  • Try to build code that's idempotent whenever possible
  • Prefer functional programming style functions: small, deterministic, 1 input, 1 output
  • Minimize coupling / dependencies
  • Avoid modifying objects received as parameter
  • Only add comments to code to explain why something was done, not how it works
  • Naming
    • classes, enums: PascalCase
    • constants, variables, functions: camelCase
    • file names: kebab-case
    • table and column names: snake_case
    • Use meaningful names, so whoever is reading the code understands what it means
    • Don’t use negative names, like notEnabled, prefer isDisabled
    • For numeric values, if the type doesn’t convey the unit, add the unit to the name
  • Typescript
    • Use types
    • Prefer const instead of let
    • Avoid any and casting from any to other types
    • Type predicates: only applicable to narrow down the type, not to force a complete type conversion
    • Prefer deconstructing parameters for functions instead of multiple parameters that might be of
      the same type
    • Don’t use null inside the app, only on code interacting with external interfaces/services,
      like DB and HTTP; convert to undefined before sending inwards into the code
    • Use async/await instead of .then()
    • Use the strict equality operator ===, don’t use abstract equality operator ==
    • When calling a Promise-returning function asynchronously (i.e., not awaiting), use .catch() to
      handle errors (see processAsyncError and emptyFunction depending on the case)
    • Date and Time
      • Always use buildDayjs() to create dayjs instances
      • Prefer dayjs.duration(...) to create duration consts and keep them as duration
  • Prefer Nullish Coalesce (??) than the OR operator (||) to provide a default value
  • Avoid creating arrow functions
  • Use truthy syntax instead of in - i.e., if (data.link) not if ('link' in data)
  • Error handling
    • Pass the original error as the new one’s cause so the stack trace is persisted
    • Error messages should have a static message - add dynamic data to MetriportError's additionalInfo prop
    • Avoid sending multiple events to Sentry for a single error
  • Global constants and variables
    • Move literals to constants declared after imports when possible (avoid magic numbers)
    • Avoid shared, global objects
  • Avoid using console.log and console.error in packages other than utils, infra and shared,
    and try to use out().log instead
  • Avoid multi-line logs
    • don't send objects as a second parameter to console.log() or out().log()
    • don't create multi-line strings when using JSON.stringify()
  • Use eslint to enforce code style
  • Use prettier to format code
  • max column length is 100 chars
  • multi-line comments use /** */
  • scripts: top-level comments go after the import
  • packages/api/src/sequelize/migrations/2025-04-28_01_alter-patient_import-add-change-log.ts
  • packages/api/src/sequelize/migrations/2025-04-28_00_create-patient_import-table.ts
  • packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts
🧠 Learnings (1)
packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts (1)
Learnt from: leite08
PR: metriport/metriport#3412
File: packages/api/src/models/medical/patient-import-mapping.ts:16-41
Timestamp: 2025-04-26T22:17:45.228Z
Learning: The patient_import_mapping table already has a unique constraint on the fields "job_id", "row_number", and "data_pipeline_request_id" defined in the migration file 2025-04-24_02_create-patient_import_mapping-table.ts, which ensures data integrity.
🧬 Code Graph Analysis (1)
packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts (1)
packages/api/src/sequelize/migrations/2025-04-28_00_create-patient_import-table.ts (2)
  • up (8-76)
  • down (78-82)
🔇 Additional comments (4)
packages/api/src/sequelize/migrations/2025-04-28_02_create-patient_import_mapping-table.ts (2)

65-71: LGTM: Down migration handles teardown properly.

The down migration correctly reverses the operations in the proper order: first removing the index, then the constraint, and finally dropping the table. This ensures clean rollback without foreign key or dependency errors.


8-9:

❌ Incorrect review comment

Potential conflict with existing migration.

Based on the retrieved learning, it appears this table and constraint were already defined in a migration from 2025-04-24 (2025-04-24_02_create-patient_import_mapping-table.ts). Verify that this isn't a duplicate migration to avoid conflicts.


🏁 Script executed:

#!/bin/bash
# Check for potential duplicate migrations
fd ".*_create-patient_import_mapping-table.ts" packages/api/src/sequelize/migrations

Length of output: 177


No duplicate migration found
The fd search in packages/api/src/sequelize/migrations only returns the 2025-04-28_02_create-patient_import_mapping-table.ts file—there is no earlier 2025-04-24_02_create-patient_import_mapping-table.ts. You can safely ignore the potential conflict raised.

Likely an incorrect or invalid review comment.

packages/api/src/sequelize/migrations/2025-04-28_01_alter-patient_import-add-change-log.ts (1)

6-13: LGTM: Well-structured function for trigger creation.

The function getChangeTriggerCreateCmd() provides a clean way to generate the SQL command for creating the trigger, making the code more maintainable.

packages/api/src/sequelize/migrations/2025-04-28_00_create-patient_import-table.ts (1)

78-82: LGTM: Down migration properly drops the table.

The down migration correctly drops the table within a transaction, ensuring proper cleanup.

@leite08 leite08 added this pull request to the merge queue Apr 28, 2025
Merged via the queue into develop with commit 8a08067 Apr 28, 2025
40 checks passed
@leite08 leite08 deleted the 2330-bulk-import-db branch April 28, 2025 17:01
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