10000 PATCH RELEASE ENG-413 Load all from os when no query by leite08 · Pull Request #3956 · metriport/metriport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PATCH RELEASE ENG-413 Load all from os when no query #3956

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 1 commit into from
Jun 4, 2025

Conversation

leite08
Copy link
Member
@leite08 leite08 commented Jun 4, 2025

Issues:

Dependencies

none

Description

Load all from os when no query.

Testing

  • Local
    • returns data when search term is provided
    • returns all data when search term is not provided
  • Staging
    • none
  • Sandbox
    • none
  • Production
    • none

Release Plan

  • ⚠️ This is pointing to master/production
  • Merge this

Summary by CodeRabbit

  • New Features

    • Search and filtering features now support empty or undefined queries, enabling broader and more flexible search capabilities.
  • Bug Fixes

    • Improved handling of empty or undefined search queries to prevent potential errors and ensure consistent behavior across search interfaces.
  • Documentation

    • Clarified documentation to reflect updated behavior for searches with empty or undefined queries.

Ref eng-413

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Copy link
linear bot commented Jun 4, 2025

@leite08 leite08 marked this pull request as ready for review June 4, 2025 16:49
Copy link
coderabbitai bot commented Jun 4, 2025

Walkthrough

The changes standardize and clarify the handling of optional search query parameters across multiple modules by updating type annotations from mandatory strings to string | undefined. Associated logic is revised to safely handle undefined values, and some redundant early returns are removed to let downstream services handle empty queries. Constants and checks are improved for clarity and maintainability.

Changes

File(s) Change Summary
.../command/consolidated/search/document-reference/search.ts Updated contentFilter parameter types from string to string | undefined in three functions; removed early return for falsy filter in one function.
.../command/consolidated/search/fhir-resource/search-consolidated-direct.ts Removed fallback to getConsolidatedPatientData; now always calls searchPatientConsolidated with passed query.
.../command/consolidated/search/fhir-resource/search-consolidated.ts Changed query parameter types in two functions to string | undefined; updated JSDoc and logging details.
.../external/opensearch/file/file-searcher-direct.ts Introduced MAX_DOCS_TO_RETURN constant; improved truthy checks for query; added pagination comment.
.../external/opensearch/file/file-searcher.ts Changed query property in SearchRequest type to string | undefined.
.../external/opensearch/lexical/fhir-searcher.ts Changed query property in SearchRequest type to string | undefined.
.../external/opensearch/lexical/query.ts Changed query in LexicalSearchParams to string | undefined; updated code to safely handle undefined queries.
.../external/opensearch/shared/query.ts Updated cleanupQuery to accept and return string | undefined; added guard for falsy input.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SearchModule
    participant OpenSearchService

    Client->>SearchModule: searchDocuments(contentFilter: string | undefined)
    SearchModule->>OpenSearchService: search with contentFilter (may be undefined)
    OpenSearchService-->>SearchModule: search results
    SearchModule-->>Client: results
Loading
sequenceDiagram
    participant Client
    participant SearchConsolidatedDirect

    Client->>SearchConsolidatedDirect: search(query: string | undefined)
    SearchConsolidatedDirect->>SearchPatientConsolidated: searchPatientConsolidated(query)
    SearchPatientConsolidated-->>SearchConsolidatedDirect: results
    SearchConsolidatedDirect-->>Client: results
Loading

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: C0AC4A7CA87F0000: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-06-04T16_51_49_005Z-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 de13fe1 and ae11340.

📒 Files selected for processing (8)
  • packages/core/src/command/consolidated/search/document-reference/search.ts (3 hunks)
  • packages/core/src/command/consolidated/search/fhir-resource/search-consolidated-direct.ts (1 hunks)
  • packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts (3 hunks)
  • packages/core/src/external/opensea 8000 rch/file/file-searcher-direct.ts (2 hunks)
  • packages/core/src/external/opensearch/file/file-searcher.ts (1 hunks)
  • packages/core/src/external/opensearch/lexical/fhir-searcher.ts (1 hunks)
  • packages/core/src/external/opensearch/lexical/query.ts (4 hunks)
  • packages/core/src/external/opensearch/shared/query.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/core/src/external/opensearch/file/file-searcher-direct.ts
  • packages/core/src/external/opensearch/lexical/fhir-searcher.ts
  • packages/core/src/command/consolidated/search/fhir-resource/search-consolidated-direct.ts
  • packages/core/src/external/opensearch/file/file-searcher.ts
  • packages/core/src/external/opensearch/lexical/query.ts
  • packages/core/src/external/opensearch/shared/query.ts
  • packages/core/src/command/consolidated/search/document-reference/search.ts
  • packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts
🧠 Learnings (3)
packages/core/src/command/consolidated/search/fhir-resource/search-consolidated-direct.ts (1)
Learnt from: leite08
PR: metriport/metriport#3942
File: packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts:48-55
Timestamp: 2025-06-01T13:42:46.270Z
Learning: In the consolidated search architecture, SearchConsolidatedParams interface allows optional query to support different implementation strategies. The searchPatientConsolidated function requires a defined query parameter because it's only called when query is guaranteed to be present. When query is undefined, SearchConsolidatedDirect branches to use getConsolidatedPatientData instead. This design pattern allows interface flexibility while maintaining implementation specificity.
packages/core/src/external/opensearch/lexical/query.ts (1)
Learnt from: leite08
PR: metriport/metriport#3914
File: packages/core/src/external/opensearch/lexical/lexical-search.ts:25-27
Timestamp: 2025-05-29T21:05:34.679Z
Learning: In packages/core/src/external/opensearch/lexical/lexical-search.ts, the `isMatchQuery` determination is intentionally performed on the raw query string before cleanup. This means leading whitespace before a prefix (like "   $foo") will be treated as a match query rather than simple_query_string, which is the desired behavior.
packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts (1)
Learnt from: leite08
PR: metriport/metriport#3942
File: packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts:48-55
Timestamp: 2025-06-01T13:42:46.270Z
Learning: In the consolidated search architecture, SearchConsolidatedParams interface allows optional query to support different implementation strategies. The searchPatientConsolidated function requires a defined query parameter because it's only called when query is guaranteed to be present. When query is undefined, SearchConsolidatedDirect branches to use getConsolidatedPatientData instead. This design pattern allows interface flexibility while maintaining implementation specificity.
🧬 Code Graph Analysis (1)
packages/core/src/external/opensearch/lexical/query.ts (1)
packages/core/src/external/opensearch/shared/query.ts (1)
  • simpleQueryStringPrefix (3-3)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (18)
packages/core/src/external/opensearch/lexical/fhir-searcher.ts (1)

21-21: LGTM: Query parameter correctly made optional.

The type change from string to string | undefined aligns with the PR objective to support loading all data when no query is provided.

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

7-7: LGTM: Interface correctly updated for optional query.

The type change is consistent with the codebase-wide update to support optional search queries.

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

8-9: Good: Magic number replaced with meaningful constant.

The constant MAX_DOCS_TO_RETURN improves readability and the TODO comment appropriately identifies the need for pagination.


27-27: LGTM: Consistent use of the defined constant.

Using MAX_DOCS_TO_RETURN instead of the magic number maintains consistency with the constant definition.


31-31: Excellent: Safer condition check for optional query.

The change from actualQuery.length > 0 to actualQuery && actualQuery.length > 0 prevents potential runtime errors when actualQuery is undefined, which is now possible with the updated type definitions.

packages/core/src/external/opensearch/shared/query.ts (1)

53-54: LGTM: Function correctly updated to handle optional queries.

The signature change to accept string | undefined and the guard clause if (!query) return query; properly handle the new optional query parameter while maintaining the existing cleanup logic for valid strings.

packages/core/src/command/consolidated/search/fhir-resource/search-consolidated-direct.ts (1)

35-35: LGTM! Architectural simplification aligns with updated search behavior.

The change to unconditionally call searchPatientConsolidated with the query parameter (which can now be undefined) simplifies the logic and aligns with the PR objective. The updated searchPatientConsolidated function now handles both scenarios internally - returning filtered results when a query is provided and all resources when no query is provided.

packages/core/src/external/opensearch/lexical/query.ts (4)

12-12: LGTM! Type signature correctly allows optional queries.

The change to string | undefined enables the function to handle cases where no search query is provided, supporting the PR's objective to load all data when no query is specified.


25-25: LGTM! Safe handling of optional query parameter.

The optional chaining prevents runtime errors when query is undefined, and the logic correctly determines query type based on prefix presence.


34-46: LGTM! Proper defensive programming for undefined queries.

The truthy check ensures safe access to actualQuery.length and provides appropriate fallback behavior. When no query is provided, the search will include only patient filters, effectively returning all resources for the patient.


58-68: LGTM! Consistent handling across query types.

The same defensive pattern is correctly applied for simple_query_string searches, ensuring consistent behavior regardless of query type.

packages/core/src/command/consolidated/search/fhir-resource/search-consolidated.ts (4)

45-46: LGTM! Clear documentation of new behavior.

The updated JSDoc clearly explains that undefined or empty queries will return all resources, which aligns perfectly with the PR objective to "load all from os when no query."


53-53: LGTM! Parameter type supports optional queries.

The type change enables the function to handle both search scenarios (with and without query) in a unified manner, eliminating the need for separate code paths.


122-122: LGTM! Consistent parameter typing across search functions.

The type change maintains consistency with the parent function and ensures proper handling of optional queries throughout the search pipeline.


162-162: LGTM! Enhanced logging for better debugging.

Including the count of missing reference IDs in the log message provides valuable debugging information without compromising performance or security.

packages/core/src/command/consolidated/search/document-reference/search.ts (3)

36-36: LGTM! Explicit typing improves clarity.

The explicit string | undefined type annotation clearly communicates that content filtering is optional, supporting scenarios where all documents should be returned.


66-66: LGTM! Consistent parameter typing.

The explicit typing maintains consistency across all document search functions and clearly indicates optional filtering behavior.


91-91: LGTM! Enables flexible search behavior.

The optional contentFilter parameter allows the search service to handle both filtered and unfiltered scenarios, supporting the PR's objective to load all data when no query is provided.

✨ 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 added this pull request to the merge queue Jun 4, 2025
Merged via the queue into master with commit 0667758 Jun 4, 2025
17 checks passed
@leite08 leite08 deleted the eng-413-load-all-from-os-when-no-query branch June 4, 2025 17:05
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