Skip to content

Conversation

thomasyopes
Copy link
Contributor

@thomasyopes thomasyopes commented Jun 19, 2025

Issues:

Dependencies

Upstream: https://github.com/metriport/metriport-internal/pull/3050

Description

Testing

Check each PR.

Release Plan

  • ⚠️ Points to master
  • ⚠️ This contains a DB migration
  • Upstream dependencies are met/released
  • Merge this

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced advanced patient job management capabilities, including scheduling, immediate execution, cancellation, failure handling, and runtime data updates.
    • Added endpoints to start scheduled jobs, retrieve/filter jobs by various criteria, and manage job runtime data.
    • Added support for new job status "cancelled" and enhanced job status transition validation.
    • Integrated AWS SQS and Lambda-based job processing infrastructure with monitoring, scheduling, and concurrency controls.
    • Added API and internal routes for EHR job execution and resource diff bundle creation.
  • Improvements

    • Expanded patient job data model with new fields for scheduling, cancellation, failure timestamps, run URLs, and runtime data.
    • Enhanced validation for ISO date/time formats and improved error handling across job operations.
    • Improved logging and response handling for job-related API requests.
    • Refined configuration and environment variable management for job processing.
  • Bug Fixes

    • Fixed job status transition logic to prevent invalid state changes.
  • Documentation

    • Added and updated route and API documentation for new and existing endpoints.
  • Chores

    • Refactored and reorganized code for better maintainability, type safety, and consistency.
    • Updated configuration and infrastructure code to support new job processing features and AWS resource integration.

Thomas Yopes and others added 30 commits June 10, 2025 17:08
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-281

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Ref: ENG-433

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

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

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… eng-433-scheduler-for-patient-job

Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-433

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

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

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

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

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

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

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

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

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

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

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

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… eng-433-scheduler-for-patient-job

Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-433

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

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

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

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

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

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

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Thomas Yopes and others added 2 commits June 19, 2025 15:01
Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
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

🧹 Nitpick comments (1)
packages/infra/lib/jobs/jobs-stack.ts (1)

45-45: Consider using long polling to reduce costs.

Setting waitTime: Duration.seconds(0) disables long polling, which can increase the number of empty API calls and associated costs. Consider using long polling with a wait time of 1-20 seconds.

-      waitTime: Duration.seconds(0),
+      waitTime: Duration.seconds(20),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f7f638 and a641412.

📒 Files selected for processing (1)
  • packages/infra/lib/jobs/jobs-stack.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/infra/lib/jobs/jobs-stack.ts
⏰ Context from checks skipped due to timeout of 90000ms (24)
  • GitHub Check: secrets_cdk_stack / deploy
  • GitHub Check: ihe_stack / deploy
  • GitHub Check: infra-api-lambdas / deploy
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
🔇 Additional comments (3)
packages/infra/lib/jobs/jobs-stack.ts (3)

1-18: LGTM!

Imports are well-organized and constants follow the coding guidelines by being declared after imports.


50-55: LGTM!

Well-structured interface definition with proper typing.


132-134: Document when API_URL is set to avoid confusion.

The comment indicates that API_URL is set later in the api-stack. Consider adding more context about when this happens and ensure the Lambda doesn't execute before this environment variable is properly configured.

#!/bin/bash
# Description: Verify where API_URL is set and how it's used in the Lambda

# Search for where API_URL is set in api-stack files
rg -A 5 "API_URL.*=" --glob "**/api-stack*"

# Search for API_URL usage in the Lambda handler
fd -e ts "run-job" packages/lambdas/src/job/patient --exec rg -A 3 "API_URL"

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.

3 participants