Skip to content

Conversation

thomasyopes
Copy link
Contributor

@thomasyopes thomasyopes commented May 1, 2025

Ref: ENG-82

Ref: #1040

Issues:

Description

  • changing pagination end condition

Release Plan

  • Merge this

Summary by CodeRabbit

  • Bug Fixes
    • Improved appointment pagination to ensure all appointments, including those without attendees, are correctly included in pagination results.
  • Chores
    • Updated webhook signature verification to use context-specific functions for improved clarity and accuracy.

Ref: ENG-82

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Copy link

linear bot commented May 1, 2025

Copy link

coderabbitai bot commented May 1, 2025

Walkthrough

The change updates the source of the last appointment used for pagination in the paginateAppointments function within the getAppointments method of the Healthie EHR integration. Previously, the last appointment was selected from the filtered list of appointments that have attendees. After the change, the last appointment is taken from the original appointments array returned by the API, regardless of attendee presence. Additionally, webhook signature verification functions were renamed for clarity and their imports updated accordingly in Elation and Healthie EHR authentication middleware.

Changes

File Change Summary
packages/core/src/external/ehr/healthie/index.ts Modified getAppointments to use the original appointments array for determining pagination cursor.
packages/core/src/external/ehr/webhook.ts Renamed verifyWebhookSignatureEd25519 to verifyWebhookSignatureEd25519Elation; renamed verifySignature to verifyWebhookSignatureHealthie. Added clarifying comments.
packages/api/src/routes/ehr/elation/auth/middleware.ts Updated import and usage of webhook signature verification function to verifyWebhookSignatureEd25519Elation.
packages/api/src/routes/ehr/healthie/auth/middleware.ts Updated import and usage of webhook signature verification function to verifyWebhookSignatureHealthie.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HealthieIntegration
    participant HealthieAPI

    Client->>HealthieIntegration: getAppointments(request)
    HealthieIntegration->>HealthieAPI: Fetch appointments
    HealthieAPI-->>HealthieIntegration: Return appointments[]
    HealthieIntegration->>HealthieIntegration: Filter appointments with attendees
    HealthieIntegration->>HealthieIntegration: Determine last appointment from original appointments[]
    HealthieIntegration-->>Client: Return paginated appointments and nextCursor
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 98e82f1 and 6d2a2d7.

📒 Files selected for processing (3)
  • packages/api/src/routes/ehr/elation/auth/middleware.ts (2 hunks)
  • packages/api/src/routes/ehr/healthie/auth/middleware.ts (2 hunks)
  • packages/core/src/external/ehr/webhook.ts (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/api/src/routes/ehr/elation/auth/middleware.ts
  • packages/core/src/external/ehr/webhook.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/api/src/routes/ehr/healthie/auth/middleware.ts
🧠 Learnings (1)
packages/api/src/routes/ehr/healthie/auth/middleware.ts (1)
Learnt from: thomasyopes
PR: metriport/metriport#3771
File: packages/core/src/util/webhook.ts:34-45
Timestamp: 2025-05-01T16:10:45.255Z
Learning: The webhook signature verification code in packages/core/src/util/webhook.ts is copied directly from Healthie's documentation and should not be modified to maintain exact compliance with their implementation.
🧬 Code Graph Analysis (1)
packages/api/src/routes/ehr/healthie/auth/middleware.ts (1)
packages/core/src/external/ehr/webhook.ts (1)
  • verifyWebhookSignatureHealthie (77-96)
🔇 Additional comments (4)
packages/api/src/routes/ehr/healthie/auth/middleware.ts (4)

1-1: Import renamed to use more specific function name.

The import was updated from generic verifySignature to the more specialized verifyWebhookSignatureHealthie, which better reflects its specific purpose for Healthie webhook signature verification.


31-38: Function call updated to match renamed function.

The function call was correctly updated to match the renamed function. This change maintains the same parameters and functionality while using the more descriptive function name.

Note: According to the retrieved learning, the webhook signature verification code is copied from Healthie's documentation and should not be modified to maintain compliance. This change only renames the function without altering the verification logic.


22-51: Webhook verification function correctly applied.

The processCxIdWebhook function properly uses the webhook signature verification to authenticate requests. This implementation follows best practices by:

  1. Verifying the signature before processing webhook data
  2. Using proper error handling
  3. Only continuing execution when verification succeeds

This function maintains the functional programming style recommended in the coding guidelines by keeping operations discrete and error handling clear.


1-99: Note about PR objective alignment.

While these changes improve code clarity by using more specific function names for webhook signature verification, I don't see changes related to the PR objective "feat(healthie): change last page determination" in this file. The pagination logic updates may be in other files not included in this review.

You may want to verify that the pagination-related changes are in other files that are part of this PR but not included in this review. The changes here seem focused on function renaming rather than pagination logic.


🪧 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.

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 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.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee751be and 98e82f1.

📒 Files selected for processing (1)
  • packages/core/src/external/ehr/healthie/index.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/ehr/healthie/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: Analyze (javascript)

Ref: ENG-82

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
@thomasyopes thomasyopes added this pull request to the merge queue May 1, 2025
@thomasyopes thomasyopes mentioned this pull request May 1, 2025
2 tasks
Merged via the queue into develop with commit 26b95a7 May 1, 2025
16 checks passed
@thomasyopes thomasyopes deleted the 1040-patch-healthie branch May 1, 2025 16:55
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