8000 1040 patch leftover by thomasyopes · Pull Request #3715 · metriport/metriport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

1040 patch leftover #3715

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 4 commits into from
Apr 24, 2025
Merged

1040 patch leftover #3715

merged 4 commits into from
Apr 24, 2025

Conversation

thomasyopes
Copy link
Contributor
@thomasyopes thomasyopes commented Apr 23, 2025

Issues:

Description

  • tying dq to resource diff
  • remove wait time for computer resource diff

Release Plan

  • Merge this

Summary by CodeRabbit

  • New Features

    • Improved tracking by supporting an optional request ID for document conversion and resource diff bundle operations.
  • Chores

    • Adjusted rate limiting for resource diff computations by removing delays.
    • Lowered alert thresholds for specific queue message counts to improve monitoring responsiveness.
  • Bug Fixes

    • Corrected patient mapping condition to properly validate input length.
    • Fixed missing code block braces to ensure correct error handling.
  • Refactor

    • Simplified job entry status types to only include "failed" and "successful" statuses.
    • Removed deprecated job status validations for "waiting" and "processing".

Thomas Yopes added 2 commits April 23, 2025 16:15
Ref: ENG-47

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

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Copy link
coderabbitai bot commented Apr 23, 2025

Walkthrough

The changes introduce a new optional requestId parameter into the document conversion and resource diff bundle creation workflow. The recreateConsolidated function now accepts and forwards this requestId to the createResourceDiffBundles function, which utilizes it if provided or generates a new UUID if not. Additionally, the infrastructure configuration is updated to remove artificial delays for computing resource diffs and to lower the alarm thresholds for certain queue message counts. The job status types and validation functions were simplified and adjusted, removing some previously supported statuses and related validation functions. No other logic, control flow, or public API changes are present.

Changes

File(s) Change Summary
packages/api/src/command/medical/document/document-conversion-status.ts Updated calls to recreateConsolidated to include the new requestId parameter where appropriate.
packages/api/src/command/medical/patient/consolidated-recreate.ts Modified recreateConsolidated to accept an optional requestId parameter and forward it to createResourceDiffBundles. Function signature updated accordingly.
packages/api/src/external/ehr/create-resource-diff-bundles.ts Extended CreateResourceDiffBundlesParams with optional requestId, updated createResourceDiffBundles to use provided requestId or generate a new UUID, fixed a block scoping issue, and corrected a condition on array length.
packages/infra/lib/ehr-nested-stack.ts Removed the 500ms wait time for resource diff computation and reduced the max message count alarm thresholds for specific queues from 5,000/15,000 to 1,000.
packages/shared/src/domain/job/job-status.ts Added a new isValidJobStatus function to validate job status strings, returning true for "waiting", "processing", "completed", or "failed".
packages/shared/src/domain/job/types.ts Simplified JobEntryStatus type to only "failed" and "successful", removed extended statuses and the isValidJobStatus function, and updated isValidJobEntryStatus to reflect the simplified statuses.

Sequence Diagram(s)

sequenceDiagram
    participant DocumentStatus as calculateDocumentConversionStatus
    participant Consolidated as recreateConsolidated
    participant ResourceDiff as createResourceDiffBundles

    DocumentStatus->>Consolidated: recreateConsolidated({patient, context, conversionType, isDq, requestId})
    Consolidated->>ResourceDiff: createResourceDiffBundles({patient, context, conversionType, isDq, requestId})
    ResourceDiff->>ResourceDiff: Use requestId if provided, else generate new UUID
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 49371b1 and f0606eb.

📒 Files selected for processing (1)
  • packages/shared/src/domain/job/job-status.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/domain/job/job-status.ts

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

Copy link

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

Copy link

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

@thomasyopes thomasyopes added this pull request to the merge queue Apr 23, 2025
@thomasyopes thomasyopes removed this pull request from the merge queue due to a manual request Apr 23, 2025
Ref: ENG-47

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

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

@thomasyopes thomasyopes added this pull request to the merge queue Apr 23, 2025
Copy link

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

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/shared/src/domain/job/types.ts (1)

6-10: Confirm downstream impact of shrinking JobEntryStatus to only “failed” | “successful”

All references th 10000 at previously expected "waiting" / "processing" entry-level states will now fail to compile or, if using string literals dynamically, misbehave at runtime.
Please double-check:

  • Migration scripts / DB constraints
  • API payload validators (e.g., Zod, Joi, io-ts)
  • Analytics dashboards expecting the old states

If those paths are already refactored, consider mirroring the approach used in job-status.ts for maintainability:

const jobEntryStatus = ["failed", "successful"] as const;
export type JobEntryStatus = typeof jobEntryStatus[number];

export function isValidJobEntryStatus(
  status: string
): status is JobEntryStatus {
  return (jobEntryStatus as readonly string[]).includes(status as JobEntryStatus);
}

This avoids hard-coding literals in multiple places.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48ae836 and 49371b1.

📒 Files selected for processing (3)
  • packages/api/src/external/ehr/create-resource-diff-bundles.ts (3 hunks)
  • packages/shared/src/domain/job/job-status.ts (1 hunks)
  • packages/shared/src/domain/job/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/api/src/external/ehr/create-resource-diff-bundles.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/shared/src/domain/job/job-status.ts
  • packages/shared/src/domain/job/types.ts

Comment on lines 6 to 12
export function isValidJobStatus(status: string): status is JobStatus {
return (
status === "waiting" ||
status === "processing" ||
status === "successful" ||
status === "failed"
);
Copy link
@coderabbitai coderabbitai bot Apr 23, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

“successful” is not a valid JobStatus – type guard currently lies

JobStatus is declared as the union "waiting" | "processing" | "completed" | "failed", yet the new isValidJobStatus() returns true for "successful".
This introduces two serious problems:

  1. The type-predicate now claims "successful" satisfies JobStatus, which will cause a TS error (or, if --suppressImplicitAnyIndexErrors is on, silently unsound typing).
  2. Runtime callers will believe "successful" is allowed and may persist this value, breaking every consumer that expects only the four canonical statuses (e.g. isJobDone, DB enums, analytics).

Patch the guard (and preferably DRY it up) like so:

-export function isValidJobStatus(status: string): status is JobStatus {
-  return (
-    status === "waiting" ||
-    status === "processing" ||
-    status === "successful" ||
-    status === "failed"
-  );
-}
+export function isValidJobStatus(status: string): status is JobStatus {
+  // keep implementation in sync with `jobStatus` source-of-truth
+  return (jobStatus as readonly string[]).includes(status as JobStatus);
+}

This fixes the immediate bug and ensures future edits to jobStatus automatically propagate.
(If "successful" really is a new status, add it to jobStatus, update isJobDone, database enums, etc. in the same PR.)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function isValidJobStatus(status: string): status is JobStatus {
return (
status === "waiting" ||
status === "processing" ||
status === "successful" ||
status === "failed"
);
export function isValidJobStatus(status: string): status is JobStatus {
// keep implementation in sync with `jobStatus` source-of-truth
return (jobStatus as readonly string[]).includes(status as JobStatus);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Good catch!

Copy link

Choose a reason for hiding this comment

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

@thomasyopes Great! Thank you for implementing the fix. This will ensure the type guard correctly aligns with the defined job statuses.

@thomasyopes thomasyopes removed this pull request from the merge queue due to a manual request Apr 23, 2025
Ref: ENG-47

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

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

@thomasyopes thomasyopes enabled auto-merge April 23, 2025 23:58
@thomasyopes thomasyopes added this pull request to the merge queue Apr 23, 2025
Copy link

⚠️ This PR is titled PATCH or RELEASE but its not targeting the master branch. Please update the base branch to master or update the PR title.

Merged via the queue into develop with commit d197068 Apr 24, 2025
18 checks passed
@thomasyopes thomasyopes deleted the 1040-patch-leftover branch April 24, 2025 00: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.

3 participants
0