8000 RELEASE Retry CW + Validate before IO + Don't load bundle unnecessarily by leite08 · Pull Request #3783 · metriport/metriport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RELEASE Retry CW + Validate before IO + Don't load bundle unnecessarily #3783

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

Closed
wants to merge 19 commits into from

Conversation

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

Issues:

Dependencies

none

Description

Testing

Check each PR.

Release Plan

  • ⚠️ Points to master
  • Release NPM packages
  • Merge this

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for retrying certain operations on internal server errors when interacting with CommonWell APIs.
    • Enhanced analytics tracking for consolidated patient data queries, including event reporting and progress tracking.
    • Improved error handling with unified status code extraction and new type guard for error types.
    • Improved patient data handling by passing patient objects directly in data contribution and consolidation workflows.
  • Bug Fixes

    • Improved consistency in handling patient objects and request identifiers across data contribution and consolidation workflows.
    • Ensured retry logic and error status code extraction are more robust throughout the application.
  • Chores

    • Updated multiple internal and external package versions to ensure compatibility and stability.
    • Applied Bedrock policy unconditionally to relevant Lambda functions for consistent configuration.

8000

leite08 added 12 commits April 30, 2025 19:02
Ref eng-141

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

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

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

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Backmerge master into develop
Ref eng-237

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

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

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

 - api@1.27.2-alpha.0
 - @metriport/api-sdk@14.14.2-alpha.0
 - @metriport/carequality-cert-runner@1.18.2-alpha.0
 - @metriport/carequality-sdk@1.6.2-alpha.0
 - @metriport/commonwell-cert-runner@1.26.2-alpha.0
 - @metriport/commonwell-jwt-maker@1.24.2-alpha.0
 - @metriport/commonwell-sdk@5.9.0-alpha.0
 - @metriport/core@1.24.2-alpha.0
 - @metriport/ihe-gateway-sdk@0.19.2-alpha.0
 - infrastructure@1.22.2-alpha.0
 - mllp-server@0.3.2-alpha.0
 - @metriport/shared@0.23.2-alpha.0
 - utils@1.25.2-alpha.0

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
…ibution

ENG-238 Validate contributed bundle before hitting the DB
…doesnt-load-bundle

ENG-191 Only load the bundle when converting
Copy link
coderabbitai bot commented May 5, 2025

Walkthrough

This set of changes introduces retry logic for HTTP 500 errors in the CommonWell SDK, updates several package versions and dependencies, and modifies the handling of consolidated patient data and data contr 8000 ibution workflows. The CommonWell client now accepts options for retrying failed requests. The consolidated data flow is refactored to propagate a requestId and to centralize analytics event reporting. The handleDataContribution function now requires a full Patient object instead of a patient ID. Additional utility and type safety improvements are made, such as a new type guard for Metriport errors and a function for retrieving consolidated queries by request ID. The Bedrock policy is now always added to a Lambda function regardless of configuration.

Changes

File(s) Change Summary
packages/api-sdk/package.json, packages/carequality-cert-runner/package.json, packages/carequality-sdk/package.json, packages/commonwell-cert-runner/package.json, packages/commonwell-jwt-maker/package.json, packages/commonwell-sdk/package.json, packages/core/package.json, packages/ihe-gateway-sdk/package.json, packages/infra/package.json, packages/mllp-server/package.json, packages/shared/package.json, packages/utils/package.json Incremented package versions and updated dependency versions where applicable.
packages/commonwell-sdk/src/client/commonwell.ts Added retry logic for HTTP 500 errors using new CommonWellOptions and OnError500Options types; constructor and registerPatient updated to support retries; new private retry method added.
packages/commonwell-sdk/src/common/metriport-error.ts Removed the MetriportError class definition (now provided by shared package).
packages/shared/src/error/metriport-error.ts Added type guard function isMetriportError for identifying Metriport errors.
packages/shared/src/net/retry.ts Enhanced getHttpStatusFromError to recognize MetriportError status codes using the new type guard; changed error cause check to truthiness.
packages/api/src/external/commonwell/api.ts Updated CommonWell API construction to use new retry options for HTTP 500 errors.
packages/api/src/command/medical/patient/consolidated-get.ts Added requestId propagation to consolidated data retrieval functions; removed analytics tracking from this layer.
packages/api/src/command/medical/patient/convert-fhir-bundle.ts Extended handleBundleToMedicalRecord to accept requestId and report analytics after bundle conversion.
packages/api/src/command/medical/patient/consolidated-recreate.ts Modified recreateConsolidated to use an alternate flow when conversionType is absent.
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts Refactored handleDataContribution to accept a Patient object instead of a patient ID; adjusted internal logic accordingly.
packages/api/src/routes/medical/patient.ts Updated putConsolidated to pass the full Patient object to handleDataContribution.
packages/core/src/command/consolidated/get-snapshot-local.ts Added analytics event reporting after consolidated snapshot execution; unified bundle handling logic.
packages/core/src/domain/patient.ts Added getConsolidatedQueryByRequestId utility for retrieving queries by request ID.
packages/api/src/routes/helpers/default-error-handler.ts Unified error status code handling to check both statusCode and status properties.
packages/infra/lib/lambdas-nested-stack.ts Removed conditional check for bedrock config; Bedrock policy now always added to Lambda functions.

Sequence Diagram(s)

CommonWell Client Retry Logic

sequenceDiagram
    participant Caller
    participant CommonWell
    participant Network

    Caller->>CommonWell: registerPatient(meta, patient)
    CommonWell->>CommonWell: executeWithRetriesOn500(fn)
    alt onError500.retry == true
        CommonWell->>Network: API call (retry on 500)
        Network-->>CommonWell: Response (may retry up to 3 times)
    else onError500.retry == false
        CommonWell->>Network: API call (no retry)
        Network-->>CommonWell: Response
    end
    CommonWell-->>Caller: Patient result
Loading

Consolidated Data Contribution Flow

sequenceDiagram
    participant Route
    participant handleDataContribution
    participant handleBundleToMedicalRecord
    participant Analytics

    Route->>handleDataContribution: ({ requestId, patient, cxId, bundle })
    handleDataContribution->>handleBundleToMedicalRecord: ({ bundle, patient, requestId, ... })
    handleBundleToMedicalRecord->>Analytics: analytics('consolidatedQuery', ...)
    handleBundleToMedicalRecord-->>handleDataContribution: Converted bundle
    handleDataContribution-->>Route: Result
Loading

Possibly related PRs

  • metriport/metriport#3692: Modifies recreateConsolidated to conditionally handle consolidation retrieval based on the presence of conversionType, introducing an alternate pathway—directly related to the changes here.
  • metriport/metriport#3785: Updates package versions and dependencies for several packages, overlapping with the version and dependency updates in this PR.
  • metriport/metriport#3775: Refactors handleDataContribution to accept a Patient object instead of a patient ID, directly related to the changes in this PR.

📜 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 6e08b6f and 483d57b.

📒 Files selected for processing (1)
  • packages/api/src/__tests__/e2e/mapi/parts/consolidated/consolidated-template.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/api/src/tests/e2e/mapi/parts/consolidated/consolidated-template.json

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

Backmerge master into develop
leite08 added 2 commits May 5, 2025 13:47
Ref: #000

 - api@1.27.2
 - @metriport/api-sdk@14.14.2
 - @metriport/carequality-cert-runner@1.18.2
 - @metriport/carequality-sdk@1.6.2
 - @metriport/commonwell-cert-runner@1.26.2
 - @metriport/commonwell-jwt-maker@1.24.2
 - @metriport/commonwell-sdk@5.9.0
 - @metriport/core@1.24.2
 - @metriport/ihe-gateway-sdk@0.19.2
 - infrastructure@1.22.2
 - mllp-server@0.3.2
 - @metriport/shared@0.23.2
 - utils@1.25.2

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
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 (5)
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)

45-54: Good implementation of alternative flow when conversion type is absent.

The implementation now provides two paths:

  1. Using getConsolidated when conversion type is specified
  2. Using the snapshot connector with isAsync: false when conversion type is missing

This aligns with the PR objectives to avoid unnecessary bundle loading.

Consider updating the error message in line 64 to reflect that either getConsolidated or the snapshot connector might be used:

-    processAsyncError(`Post-DQ getConsolidated`, log)(err);
+    processAsyncError(`Post-DQ consolidated recreation`, log)(err);
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (2)

43-49: Improved parallel execution by removing patient fetch.

The Promise.all now only needs to fetch the organization since patient is passed directly, improving efficiency.

The log message on line 50 should be updated to reflect that we're no longer fetching the patient:

-  log(`${Date.now() - mainStartedAt}ms to get org and patient, and store on S3`);
+  log(`${Date.now() - mainStartedAt}ms to get org and store bundle on S3`);

53-56: Update log timing description to match code flow.

The validation timing log message refers to hydration and validation steps that now occur before the timing starts.

Update the log message to reflect when these operations actually occur:

-  log(`${Date.now() - validationStartedAt}ms to hydrate, validate, and check limits`);
+  log(`${Date.now() - validationStartedAt}ms to convert organization to FHIR and check resource limits`);
packages/core/src/command/consolidated/get-snapshot-local.ts (1)

128-138: Add analytics tracking for consolidated query performance.

This implementation tracks query duration and resource count, aligning with the PR objectives for improved monitoring.

Consider adding a null check for the consolidated query progress:

-    const currentConsolidatedProgress = getConsolidatedQueryByRequestId(patient, requestId);
-    analytics({
-      distinctId: cxId,
-      event: EventTypes.consolidatedQuery,
-      properties: {
-        patientId: patientId,
-        conversionType: "bundle",
-        duration: elapsedTimeFromNow(currentConsolidatedProgress?.startedAt),
-        resourceCount: resultBundle.entry?.length,
-      },
-    });
+    const currentConsolidatedProgress = getConsolidatedQueryByRequestId(patient, requestId);
+    if (requestId) {
+      analytics({
+        distinctId: cxId,
+        event: EventTypes.consolidatedQuery,
+        properties: {
+          patientId: patientId,
+          conversionType: "bundle",
+          duration: currentConsolidatedProgress?.startedAt 
+            ? elapsedTimeFromNow(currentConsolidatedProgress.startedAt)
+            : undefined,
+          resourceCount: resultBundle.entry?.length,
+        },
+      });
+    }
packages/api/src/command/medical/patient/convert-fhir-bundle.ts (1)

88-98: Add analytics tracking for consolidated query performance.

This implementation complements the tracking added in get-snapshot-local.ts, centralizing analytics for medical record conversions.

Similar to the previous file, consider adding checks for requestId and query progress:

-    const currentConsolidatedProgress = getConsolidatedQueryByRequestId(patient, requestId);
-    analytics({
-      distinctId: patient.cxId,
-      event: EventTypes.consolidatedQuery,
-      properties: {
-        patientId: patient.id,
-        conversionType,
-        duration: elapsedTimeFromNow(currentConsolidatedProgress?.startedAt),
-        resourceCount: newBundle.entry?.length,
-      },
-    });
+    if (requestId) {
+      const currentConsolidatedProgress = getConsolidatedQueryByRequestId(patient, requestId);
+      analytics({
+        distinctId: patient.cxId,
+        event: EventTypes.consolidatedQuery,
+        properties: {
+          patientId: patient.id,
+          conversionType,
+          duration: currentConsolidatedProgress?.startedAt 
+            ? elapsedTimeFromNow(currentConsolidatedProgress.startedAt)
+            : undefined,
+          resourceCount: newBundle.entry?.length,
+        },
+      });
+    }

Also, consider using a try/catch block to prevent analytics errors from affecting the main function flow:

if (requestId) {
  try {
    // Analytics code here
  } catch (err) {
    log(`Failed to send analytics: ${err}`);
  }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a52dba6 and 47e20bd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (26)
  • packages/api-sdk/package.json (2 hunks)
  • packages/api/package.json (1 hunks)
  • packages/api/src/command/medical/patient/consolidated-get.ts (5 hunks)
  • packages/api/src/command/medical/patient/consolidated-recreate.ts (2 hunks)
  • packages/api/src/command/medical/patient/convert-fhir-bundle.ts (3 hunks)
  • packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (2 hunks)
  • packages/api/src/external/commonwell/api.ts (3 hunks)
  • packages/api/src/routes/helpers/default-error-handler.ts (1 hunks)
  • packages/api/src/routes/medical/patient.ts (1 hunks)
  • packages/carequality-cert-runner/package.json (2 hunks)
  • packages/carequality-sdk/package.json (1 hunks)
  • packages/commonwell-cert-runner/package.json (2 hunks)
  • packages/commonwell-jwt-maker/package.json (2 hunks)
  • packages/commonwell-sdk/package.json (2 hunks)
  • packages/commonwell-sdk/src/client/commonwell.ts (8 hunks)
  • packages/commonwell-sdk/src/common/metriport-error.ts (0 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/command/consolidated/get-snapshot-local.ts (7 hunks)
  • packages/core/src/domain/patient.ts (1 hunks)
  • packages/ihe-gateway-sdk/package.json (2 hunks)
  • packages/infra/package.json (1 hunks)
  • packages/mllp-server/package.json (1 hunks)
  • packages/shared/package.json (1 hunks)
  • packages/shared/src/error/metriport-error.ts (1 hunks)
  • packages/shared/src/net/retry.ts (2 hunks)
  • packages/utils/package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/commonwell-sdk/src/common/metriport-error.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/medical/patient.ts
  • packages/shared/src/net/retry.ts
  • packages/api/src/external/commonwell/api.ts
  • packages/shared/src/error/metriport-error.ts
  • packages/api/src/routes/helpers/default-error-handler.ts
  • packages/core/src/domain/patient.ts
  • packages/api/src/command/medical/patient/consolidated-recreate.ts
  • packages/api/src/command/medical/patient/consolidated-get.ts
  • packages/core/src/command/consolidated/get-snapshot-local.ts
  • packages/api/src/command/medical/patient/convert-fhir-bundle.ts
  • packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts
  • packages/commonwell-sdk/src/client/commonwell.ts
🧠 Learnings (2)
packages/api-sdk/package.json (1)
Learnt from: leite08
PR: metriport/metriport#3463
File: packages/api-sdk/src/medical/models/patient.ts:1-1
Timestamp: 2025-03-19T13:58:17.253Z
Learning: When changes are made to SDK packages (`api-sdk`, `commonwell-sdk`, `carequality-sdk`) or `packages/shared` in the Metriport codebase, alpha versions need to be published to NPM before merging the PR.
packages/shared/src/error/metriport-error.ts (1)
Learnt from: husainsyed
PR: metriport/metriport#3655
File: packages/shared/src/validators/driver-license/index.ts:1-89
Timestamp: 2025-04-10T21:17:35.036Z
Learning: MetriportError constructor takes three separate parameters: message (string), cause (optional unknown), and additionalInfo (optional object), not a single object with these properties. The correct instantiation is: new MetriportError(message, cause, additionalInfo).
🧬 Code Graph Analysis (4)
packages/api/src/routes/medical/patient.ts (1)
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (1)
  • handleDataContribution (19-90)
packages/shared/src/net/retry.ts (1)
packages/shared/src/error/metriport-error.ts (1)
  • isMetriportError (13-15)
packages/api/src/external/commonwell/api.ts (1)
packages/commonwell-sdk/src/client/commonwell.ts (2)
  • CommonWellOptions (71-74)
  • CommonWell (76-1017)
packages/commonwell-sdk/src/client/commonwell.ts (2)
packages/shared/src/common/retry.ts (1)
  • ExecuteWithRetriesOptions (21-45)
packages/shared/src/net/retry.ts (2)
  • executeWithNetworkRetries (108-135)
  • defaultOptionsRequestNotAccepted (26-33)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: api / deploy
  • GitHub Check: mllp-server / deploy
  • GitHub Check: infra-api-lambdas / deploy
  • GitHub Check: infra-hl7-notification / deploy
🔇 Additional comments (54)
packages/utils/package.json (1)

3-3: Approve version bump to 1.25.2
The version increment is consistent with the coordinated release plan and introduces no breaking changes.

packages/api/package.json (1)

3-3: Version bump to 1.27.2
The package version has been correctly incremented to align with the coordinated release across related Metriport packages.

packages/infra/package.json (1)

3-3: Approve version bump to 1.22.2
This update correctly increments the package version to align with the coordinated release across related packages.
Note: The AI-generated summary describes additional code changes that aren’t present here—this file only contains the version bump.

Likely an incorrect or invalid review comment.

packages/carequality-sdk/package.json (1)

3-3: Approve version bump to 1.6.2
The version field has been correctly updated from 1.6.1 to 1.6.2 with no other changes.

packages/shared/package.json (1)

3-3: Consistent version bump for @metriport/shared
The package version has been updated from 0.23.1 to 0.23.2 in line with the coordinated releases across the monorepo.

packages/core/package.json (1)

3-3: Consistent version bump for @metriport/core
The package version has been updated from 1.24.1 to 1.24.2 to align with the shared release plan.

packages/commonwell-sdk/package.json (2)

3-3: Consistent SDK version bump for @metriport/commonwell-sdk
The package version has been incremented from 5.8.1 to 5.9.0, matching the PR’s release strategy.


63-63: Upgrade dependency on @metriport/shared
The dependency on @metriport/shared has been updated to ^0.23.2 to reflect the new shared package version.

packages/commonwell-jwt-maker/package.json (1)

3-3: Consistent version bump for @metriport/commonwell-jwt-maker
The package version has been updated from 1.24.1 to 1.24.2, aligning with the SDK’s release.

packages/ihe-gateway-sdk/package.json (2)

3-3: Consistent version bump for @metriport/ihe-gateway-sdk
The package version has been updated from 0.19.1 to 0.19.2, consistent with the shared release increments.


56-56: Upgrade dependency on @metriport/shared
The dependency on @metriport/shared has been updated to ^0.23.2 to maintain cross-package compatibility.

packages/commonwell-cert-runner/package.json (2)

3-3: Version increment looks good.

Version has been incremented from 1.26.1 to 1.26.2 as part of the coordinated release.


45-45:

✅ Verification successful

Dependency update for CommonWell SDK aligns with release.

The dependency on @metriport/commonwell-sdk has been updated to ^5.9.0 to incorporate the new retry logic for HTTP 500 errors.


🏁 Script executed:

#!/bin/bash
# Verify that the CommonWell SDK 5.9.0 version exists on NPM
npm view @metriport/commonwell-sdk versions --json | jq 'map(select(. == "5.9.0"))' 

Length of output: 99


Approve CommonWell SDK update to ^5.9.0

Confirmed that @metriport/commonwell-sdk@5.9.0 exists on npm, and this update brings in the new retry logic for HTTP 500 errors as intended.

• packages/commonwell-cert-runner/package.json: line 45

packages/api-sdk/package.json (3)

3-3: Version increment looks good.

Version has been incremented from 14.14.1 to 14.14.2 as part of the coordinated release.


1-81: Reminder: Publish alpha version to NPM before merging.

Based on previous learnings, when changes are made to SDK packages like api-sdk, alpha versions need to be published to NPM before merging the PR.


61-62:

✅ Verification successful

Dependency updates align with the coordinated release.

The updates to both dependencies are consistent with the version changes across the ecosystem:

  • @metriport/commonwell-sdk from 5.8.1 to ^5.9.0
  • @metriport/shared from 0.23.1 to ^0.23.2

🏁 Script executed:

#!/bin/bash
# Verify that the required dependency versions exist on NPM
echo "Checking CommonWell SDK 5.9.0..."
npm view @metriport/commonwell-sdk versions --json | jq 'map(select(. == "5.9.0"))' 

echo "Checking Shared 0.23.2..."
npm view @metriport/shared versions --json | jq 'map(select(. == "0.23.2"))' 

Length of output: 329


Approve coordinated dependency updates
Verified that @metriport/commonwell-sdk@5.9.0 and @metriport/shared@0.23.2 are published on NPM and the version bumps align with the coordinated release.

• File: packages/api-sdk/package.json (lines 61–62)

  "@metriport/commonwell-sdk": "^5.9.0",
  "@metriport/shared": "^0.23.2",
packages/shared/src/error/metriport-error.ts (1)

13-15: Well-implemented type guard for MetriportError.

The isMetriportError function follows TypeScript best practices by:

  1. Using the type predicate pattern err is MetriportError to narrow down the type
  2. Correctly implementing the instance check using instanceof
  3. Taking unknown as the parameter type to enforce type safety

This will improve error handling consistency throughout the codebase.

packages/carequality-cert-runner/package.json (2)

3-3: Version increment looks good.

Version has been incremented from 1.18.1 to 1.18.2 as part of the coordinated release.


44-45:

✅ Verification successful

Dependency updates align with the coordinated release.

The updates to both dependencies are consistent with the version changes across the ecosystem:

  • @metriport/ihe-gateway-sdk from ^0.19.1 to ^0.19.2
  • @metriport/shared from ^0.23.1 to ^0.23.2

🏁 Script executed:

#!/bin/bash
# Verify that the required dependency versions exist on NPM
echo "Checking IHE Gateway SDK 0.19.2..."
npm view @metriport/ihe-gateway-sdk versions --json | jq 'map(select(. == "0.19.2"))' 

echo "Checking Shared 0.23.2..."
npm view @metriport/shared versions --json | jq 'map(select(. == "0.23.2"))' 

Length of output: 336


Dependencies updated successfully and align with coordinated release

  • File: packages/carequality-cert-runner/package.json (lines 44–45)
  • Verified that:
    • @metriport/ihe-gateway-sdk@^0.19.2 is published on NPM
    • @metriport/shared@^0.23.2 is published on NPM
  • These bumps match the ecosystem’s move from 0.19.1→0.19.2 and 0.23.1→0.23.2

All set to approve.

packages/shared/src/net/retry.ts (2)

10-10: Good import of the new type guard.

Properly importing the newly created isMetriportError type guard from the error module.


51-52: Improved error handling with type safety.

Two important improvements to the error handling:

  1. Changed from property access pattern checking with "cause" in error to a more direct truthiness check with error.cause, which is cleaner and follows the coding guidelines.

  2. Added proper type-safe error handling using the new isMetriportError type guard, enhancing the reliability of status code extraction.

packages/api/src/routes/medical/patient.ts (2)

365-365: Update to pass full patient object instead of just patient ID.

The function now correctly extracts the full patient object rather than just the ID, supporting the updated method signature of handleDataContribution.


367-367: Correctly updates handleDataContribution parameter.

This change passes the complete patient object to handleDataContribution instead of just the patient ID, ensuring proper function invocation with the updated signature.

packages/core/src/domain/patient.ts (1)

128-133: Good implementation o 8000 f a utility function.

This function provides a clean way to find a consolidated query by requestId. The implementation is:

  • Type-safe (uses proper parameter typing)
  • Functional (pure function with single input/output)
  • Concise (uses optional chaining for null safety)
packages/api/src/routes/helpers/default-error-handler.ts (1)

108-120: Improved error handling consistency.

This change enhances error handling by checking both err.statusCode and err.status properties, ensuring consistent status extraction regardless of which property is present. This is a good practice since different error implementations might use different property names.

packages/api/src/external/commonwell/api.ts (4)

9-9: Added import for CommonWellOptions.

Correctly imports the CommonWellOptions type to support the new retry configuration.


48-54: Added retry logic for HTTP 500 errors.

This configuration implements a resilient approach to handling HTTP 500 errors from CommonWell:

  • Retries up to 3 attempts
  • Uses an initial delay of 1 second
  • Follows best practices for error resilience

This is a valuable improvement that will help handle transient server errors without application failure.


58-65: Added retry options to member API constructor.

Correctly passes the retry options to the member API instance of CommonWell.


68-75: Added retry options to organization API constructor.

Correctly passes the retry options to the organization API instance of CommonWell.

packages/api/src/command/medical/patient/consolidated-recreate.ts (1)

3-4: New imports support the alternative consolidated recreation flow.

These imports enable the new code path for recreating consolidated bundle without a conversion type.

packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (4)

3-3: Import of Patient type to support the signature change.

This import enables the function to accept a full Patient object instead of just a patient ID.


19-28: Good refactoring to accept Patient object directly instead of patientId.

This change eliminates the need to fetch the patient separately, improving efficiency and aligning with the PR objectives.


30-30: Extract patientId from patient object.

This extraction maintains backward compatibility in the function implementation while using the newly passed patient object.


39-41: Good restructuring to perform normalization and validation earlier.

Moving these operations earlier in the function follows the "fail fast" principle, which can improve error handling and performance.

packages/core/src/command/consolidated/get-snapshot-local.ts (6)

11-12: Import analytics and query tracking capabilities.

These imports support the new analytics features added to track consolidated query performance.


38-39: Improved parameter destructuring.

The code now properly extracts patient and requestId from params, and patientId and cxId from patient, making the data flow more explicit.


44-44: Directly use patient object from the extracted parameters.

This change makes the code more consistent with the parameter destructuring above.


66-66: Introduce resultBundle to standardize bundle references.

This improves code consistency by using a standard variable name for the final bundle result.


69-69: Use resultBundle consistently for validation and error handling.

The code now consistently uses resultBundle where it previously used normalizedBundle.

Also applies to: 80-80


89-89: Update Promise.all array destructuring and S3 upload references.

The code correctly uses resultBundle for S3 uploads and destructures resultS3Info from the Promise results.

Also applies to: 105-105, 110-110

packages/api/src/command/medical/patient/convert-fhir-bundle.ts (3)

13-14: Import analytics and query tracking utilities.

These imports support the new analytics tracking functionality for consolidated queries.


18-18: Import elapsed time calculation utility.

This utility enables measurement of query duration for analytics purposes.


44-44: Add optional requestId parameter to enable query tracking.

This parameter allows the function to track and report analytics for specific query requests.

Also applies to: 52-52

packages/api/src/command/medical/patient/consolidated-get.ts (3)

54-54: Type modification follows consistent pattern

Adding the optional requestId parameter to GetConsolidatedPatientData type follows the existing pattern in the code and enables proper request tracing through the system.


264-264: Properly propagating requestId parameter

The requestId is now being correctly passed to getConsolidatedPatientData, which aligns with the goal of propagating this identifier throughout the data flow.


281-281: Correctly forwarding requestId to bundle conversion

The requestId is now being properly passed to handleBundleToMedicalRecord, ensuring consistent tracking throughout the process. This change works alongside the analytics centralization mentioned in the summary.

packages/commonwell-sdk/src/client/commonwell.ts (8)

1-7: Improved imports from shared package

Good use of shared utilities for error handling and retry logic. This promotes code reuse and standardization across the application.


48-52: Well-structured default options for 500 error handling

The default configuration is well-defined with conservative defaults (retry disabled), ensuring backward compatibility with existing behavior.


67-74: Well-designed type definitions for retry options

The type definitions are clean and follow TypeScript best practices. The OnError500Options type properly extends ExecuteWithRetriesOptions while adding the necessary retry flag, and CommonWellOptions provides a clear interface for configuring the client.


94-94: Private property follows naming conventions

The private onError500 property follows the established naming conventions in the class and properly encapsulates the configuration.


113-113: Backward-compatible constructor parameter

Making the options parameter optional with a default empty object ensures backward compatibility with existing code that doesn't specify options.


129-129: Proper initialization with defaults

Good use of object spreading to merge default options with user-provided options, following the best practice for handling configuration objects.


634-642: Added retry mechanism for registerPatient

The implementation correctly wraps the API call with the retry logic. This addresses the PR objective to add retry capability for the CommonWell client, specifically targeting HTTP 500 errors.


1005-1016: Well-implemented retry utility method

The executeWithRetriesOn500 method is well-designed and:

  1. Conditionally applies retry logic based on configuration
  2. Properly merges all HTTP codes to retry
  3. Specifically adds the 500 status code to the retry list
  4. Falls back to direct function execution when retries are disabled

This implementation follows functional programming principles with minimal state changes.

Ref metriport/metriport-internal#799

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
…rock-access

799 Always add permission to bedrock on FHIR Converter
leite08 added 2 commits May 5, 2025 15:09
Ref metriport/metriport-internal#1040

Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
1040 E2E: Add "text" to allergy intollerance and doc ref
Orta21
Orta21 previously approved these changes May 5, 2025
@leite08 leite08 dismissed Orta21’s stale review May 5, 2025 20:22

The merge-base changed after approval.

@leite08 leite08 enabled auto-merge May 5, 2025 20:23
Orta21
Orta21 previously approved these changes May 5, 2025
@leite08 leite08 dismissed Orta21’s stale review May 5, 2025 20:35

The merge-base changed after approval.

@leite08 leite08 disabled auto-merge May 5, 2025 20:36
Orta21
Orta21 previously approved these changes May 5, 2025
@leite08 leite08 enabled auto-merge May 5, 2025 20:40
@leite08 leite08 dismissed Orta21’s stale review May 5, 2025 20:40

The merge-base changed after approval.

Orta21
Orta21 previously approved these changes May 5, 2025
@leite08 leite08 dismissed Orta21’s stale review May 5, 2025 20:46

The merge-base changed after approval.

thomasyopes
thomasyopes previously approved these changes May 5, 2025
@leite08 leite08 dismissed thomasyopes’s stale review May 5, 2025 21:34

The merge-base changed after approval.

@leite08 leite08 disabled auto-merge May 5, 2025 21:40
@leite08 leite08 closed this May 5, 2025
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