8000 RELEASE ENG-268 Enable ingestion on consolidate recreate by leite08 · Pull Request #3917 · metriport/metriport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RELEASE ENG-268 Enable ingestion on consolidate recreate #3917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 30, 2025
Merged

Conversation

leite08
Copy link
Member
@leite08 leite08 commented May 29, 2025

Issues:

Dependencies

Description

Testing

Release Plan

  • ⚠️ Points to master
  • Merge this

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Consolidated patient data is now automatically ingested into the search engine after recreation, improving data availability in search results.
    • Search ingestion now processes patient data updates more efficiently by enabling FIFO queueing, ensuring timely and ordered updates.
    • Search queries have been optimized for better performance and configurability, enhancing search accuracy and flexibility.

leite08 added 2 commits May 29, 2025 14:39
Ref eng-268

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
…d-into-open-search_2

ENG-268 Enable ingestion on data pipeline
Copy link
linear bot commented May 29, 2025

Copy link
coderabbitai bot commented May 29, 2025

"""

Walkthrough

The change activates previously commented-out code in the patient consolidated recreate command, enabling the ingestion of consolidated patient data into the search engine after bundle recreation. It also updates the ingestion queue to use FIFO with unique deduplication IDs, adjusts queue configuration to enable FIFO and remove batching window, and refines search query construction by removing redundant cleanup and making the lexical search field configurable.

Changes

File(s) Change Summary
packages/api/src/command/medical/patient/consolidated-recreate.ts Uncommented import and invocation of consolidated data ingestion into the search engine after bundle recreation.
packages/core/src/command/consolidated/search/fhir-resource/ingest-consolidated-sqs.ts Modified ingestSingle to send FIFO SQS messages with messageGroupId set to patientId and unique messageDeduplicationId using nanoid.
packages/infra/lib/lambdas-nested-stack-settings.ts Enabled FIFO for consolidated ingestion connector queue and removed maxBatchingWindow setting from event source configuration.
packages/core/src/external/opensearch/file/file-searcher-direct.ts Removed redundant call to cleanupQuery when building simple_query_string query.
packages/core/src/external/opensearch/lexical/lexical-search.ts Replaced hardcoded "content" field with dynamic [contentFieldName] in lexical search match query.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RecreateConsolidatedFunction
    participant Ingestor
    participant SearchEngine

    User->>RecreateConsolidatedFunction: Trigger recreateConsolidated
    RecreateConsolidatedFunction->>RecreateConsolidatedFunction: Recreate consolidated bundle
    RecreateConsolidatedFunction->>Ingestor: makeIngestConsolidated()
    RecreateConsolidatedFunction->>Ingestor: ingestConsolidatedIntoSearchEngine(cxId, patientId)
    Ingestor->>SearchEngine: Ingest consolidated data
    SearchEngine-->>Ingestor: Acknowledge ingestion
    Ingestor-->>RecreateConsolidatedFunction: Complete ingestion
Loading

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error code ERR_SSL_WRONG_VERSION_NUMBER
npm error errno ERR_SSL_WRONG_VERSION_NUMBER
npm error request to https://10.0.0.28:4873/punycode/-/punycode-2.3.1.tgz failed, reason: C01C2569947F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:
npm error
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-30T00_33_59_537Z-debug-0.log


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f63f92b and 5e77007.

📒 Files selected for processing (4)
  • packages/core/src/command/consolidated/search/fhir-resource/ingest-consolidated-sqs.ts (2 hunks)
  • packages/core/src/external/opensearch/file/file-searcher-direct.ts (1 hunks)
  • packages/core/src/external/opensearch/lexical/lexical-search.ts (1 hunks)
  • packages/infra/lib/lambdas-nested-stack-settings.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/core/src/external/opensearch/lexical/lexical-search.ts
🧰 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/infra/lib/lambdas-nested-stack-settings.ts
  • packages/core/src/external/opensearch/file/file-searcher-direct.ts
  • packages/core/src/command/consolidated/search/fhir-resource/ingest-consolidated-sqs.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e-tests / E2E Tests
🔇 Additional comments (4)
packages/infra/lib/lambdas-nested-stack-settings.ts (1)

9-9: LGTM! FIFO configuration aligns with ingestion logic changes.

The change to enable FIFO (fifo: true) is correct and aligns with the corresponding changes in the ingestion SQS logic. The existing configuration (batch size of 1, max concurrency of 5) is appropriate for FIFO queues to maintain message ordering while preventing search engine overload.

packages/core/src/command/consolidated/search/fhir-resource/ingest-consolidated-sqs.ts (2)

2-2: LGTM! Appropriate import for FIFO deduplication.

The nanoid import is correctly added to support generating unique message deduplication IDs for the FIFO SQS implementation.


63-71: Excellent FIFO SQS implementation with thoughtful deduplication strategy.

The FIFO configuration is well-implemented:

  • fifo: true correctly aligns with the infrastructure changes
  • messageGroupId: patientId ensures sequential processing per patient (virtual queue per patient)
  • messageDeduplicationId: nanoid() cleverly avoids the 5-minute deduplication window that would block search engine updates after data quality completion

The comments clearly explain the reasoning for using nanoid() instead of patientId for deduplication, which prevents blocking legitimate updates within the deduplication window.

packages/core/src/external/opensearch/file/file-searcher-direct.ts (1)

33-33: Good cleanup! Removes redundant query processing.

The change correctly removes the redundant cleanupQuery() call since actualQuery (line 22) is already the result of cleanupQuery(query). This eliminates unnecessary processing while maintaining the same functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 docstrings to generate docstrings for this 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 marked this pull request as ready for review May 29, 2025 21:49
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 (1)
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)

59-65: Review the error message context and consider timing implications.

The ingestion logic is correctly implemented with proper async error handling. However, there are a couple of considerations:

  1. Error message context: The error message says "Post-DQ" but this function can be called with isDq=false, making the message potentially misleading.

  2. Timing consideration: The ingestion is triggered immediately after consolidation recreation. Ensure that the consolidated data is fully available before ingestion begins.

Consider updating the error message to be more generic:

-      .catch(processAsyncError("Post-DQ ingestConsolidatedIntoSearchEngine"));
+      .catch(processAsyncError("ingestConsolidatedIntoSearchEngine"));

Also, verify that there are no timing issues between consolidation completion and ingestion initiation.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 795c03d and f63f92b.

📒 Files selected for processing (1)
  • packages/api/src/command/medical/patient/consolidated-recreate.ts (2 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/command/medical/patient/consolidated-recreate.ts
🧠 Learnings (1)
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)
Learnt from: leite08
PR: metriport/metriport#3814
File: packages/api/src/routes/internal/medical/patient-consolidated.ts:141-174
Timestamp: 2025-05-20T21:26:26.804Z
Learning: The functionality introduced in packages/api/src/routes/internal/medical/patient-consolidated.ts is planned to be refactored in downstream PR #3857, including improvements to error handling and validation.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)

5-5: LGTM - Import correctly added for ingestion functionality.

The import statement properly brings in the factory function needed for the ingestion logic below.

@leite08
Copy link
Member Author
leite08 commented May 29, 2025

@leite08 leite08 marked this pull request as draft May 29, 2025 22:18
leite08 added 3 commits May 29, 2025 19:36
Ref eng-268

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Ref eng-268

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
…d-into-open-search_3

ENG-268 Move ingestion queue to FIFO
leite08 added 2 commits May 29, 2025 21:00
Ref eng-268

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
…d-into-open-search_4

ENG-268 Remove max batching window from ingestion queue
@leite08 leite08 added this pull request to the merge queue May 30, 2025
Merged via the queue into master with commit 44465a8 May 30, 2025
69 checks passed
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
0