Skip to content

Conversation

keshavsaharia
Copy link
Contributor

@keshavsaharia keshavsaharia commented Jun 26, 2025

metriport/metriport-internal#2995

Issues:

Dependencies

Description

Adds the missing TERM_SERVER_URL which ensures that the Surescripts bundle conversion process is able to hydrate NDC-coded medications in the generated bundle with RxNorm codes.

Testing

Validated to work correctly in staging environment when the TERM_SERVER_URL is set manually, will verify that the correct URL is being set on staging upon patching.

  • Local
    • Ran the terminology server and lookup locally
  • Staging
    • Correct bundle hydration and crosswalk when environment variable manually added in
  • Production
    • Run SurescriptsConvertPatientResponse Lambda with a payload identifier, and check the S3 generation date for the output bundle.

Release Plan

  • Merge this

Summary by CodeRabbit

  • New Features
    • Added support for configuring an optional term server URL for Surescripts-related functionality. This can now be set as an environment variable for relevant Lambda functions.

metriport/metriport-internal#1040

Signed-off-by: Keshav Saharia <keshav@metriport.com>
Copy link

linear bot commented Jun 26, 2025

Copy link

coderabbitai bot commented Jun 26, 2025

Walkthrough

An optional configuration property, termServerUrl, has been added to the SurescriptsNestedStack class and its related methods. If provided, this value is set as the TERM_SERVER_URL environment variable in Lambda functions. The relevant TypeScript interfaces and method signatures have been updated to support this property.

Changes

File(s) Change Summary
packages/infra/lib/surescripts/surescripts-stack.ts Added optional termServerUrl property to config objects, method parameters, and Lambda env vars

Sequence Diagram(s)

sequenceDiagram
    participant Config as Configuration
    participant Stack as SurescriptsNestedStack
    participant Lambda as LambdaFunction

    Config->>Stack: Instantiate with commonConfig (may include termServerUrl)
    Stack->>Lambda: setupLambda/setupLambdaAndQueue (pass termServerUrl if present)
    alt termServerUrl provided
        Stack->>Lambda: Set TERM_SERVER_URL env variable
    end
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: C0FC05DB517F0000: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-26T14_53_07_356Z-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 7f3169e and 209594b.

📒 Files selected for processing (1)
  • packages/infra/lib/surescripts/surescripts-stack.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*`: Use eslint to enforce code style Use prettier to format code Max column ...

**/*: Use eslint to enforce code style
Use prettier to format code
Max column length is 100 chars
Multi-line comments use /** */
Top-level comments go after the import (save pre-import to basic file header, like license)
Move literals to constants declared after imports when possible
File names: kebab-case

📄 Source: CodeRabbit Inference Engine (.cursorrules)

List of files the instruction was applied to:

  • packages/infra/lib/surescripts/surescripts-stack.ts
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - 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

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • packages/infra/lib/surescripts/surescripts-stack.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: leite08
PR: metriport/metriport#3814
File: packages/api/src/routes/internal/medical/patient-consolidated.ts:141-174
Timestamp: 2025-05-20T21:26:26.804Z
Learning: The functionality introduced in packages/api/src/routes/internal/medical/patient-consolidated.ts is planned to be refactored in downstream PR #3857, including improvements to error handling and validation.
Learnt from: leite08
PR: metriport/metriport#3817
File: .github/workflows/deploy-staging.yml:206-214
Timestamp: 2025-05-12T18:29:48.116Z
Learning: In the Metriport CI/CD workflows, the IHE stack deployment is intentionally triggered by general infrastructure changes (infra-lambdas) rather than having its own dedicated change detection, as it needs to stay in sync with other infrastructure components.
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.
Learnt from: leite08
PR: metriport/metriport#0
File: :0-0
Timestamp: 2025-03-05T18:43:30.389Z
Learning: For backmerge PRs at metriport/metriport, only verify two things: (1) that the source branch is `master` and destination branch is `develop`, and (2) that there's a link to at least one PR (usually a "patch" PR) in the description. No need for detailed review comments or updates to the PR description unless there's an issue with these criteria.
Learnt from: lucasdellabella
PR: metriport/metriport#3948
File: packages/infra/lib/hl7-notification-stack/constants.ts:6-14
Timestamp: 2025-06-03T14:43:16.951Z
Learning: The environment-specific IP constants (MLLP_SERVER_NLB_PROD_INTERNAL_IP_A/B and MLLP_SERVER_NLB_STAGING_INTERNAL_IP_A/B) in packages/infra/lib/hl7-notification-stack/constants.ts are used in symlinked configuration files that are not visible during codebase analysis, which is why they may appear unused despite being actively referenced.
Learnt from: keshavsaharia
PR: metriport/metriport#3885
File: packages/core/src/external/sftp/surescripts/client.ts:1-134
Timestamp: 2025-05-28T19:23:20.179Z
Learning: In packages/core/src/external/sftp/surescripts/client.ts, the SurescriptsSftpClient constructor intentionally uses config.publicKey as the SFTP password field and config.username as the SFTP username field. This is the expected configuration for Surescripts SFTP authentication.
Learnt from: keshavsaharia
PR: metriport/metriport#3887
File: packages/lambdas/src/surescripts-receive-flat-file-response.ts:11-35
Timestamp: 2025-05-22T16:36:54.189Z
Learning: The Surescripts Lambda handlers in packages/lambdas/src/ are stub implementations that will be replaced with more solid implementations later. These stubs don't require the same level of error handling and logging as production code.
packages/infra/lib/surescripts/surescripts-stack.ts (12)
Learnt from: lucasdellabella
PR: metriport/metriport#3948
File: packages/infra/lib/hl7-notification-stack/constants.ts:6-14
Timestamp: 2025-06-03T14:43:16.951Z
Learning: The environment-specific IP constants (MLLP_SERVER_NLB_PROD_INTERNAL_IP_A/B and MLLP_SERVER_NLB_STAGING_INTERNAL_IP_A/B) in packages/infra/lib/hl7-notification-stack/constants.ts are used in symlinked configuration files that are not visible during codebase analysis, which is why they may appear unused despite being actively referenced.
Learnt from: keshavsaharia
PR: metriport/metriport#3885
File: packages/core/src/external/sftp/surescripts/client.ts:1-134
Timestamp: 2025-05-28T19:23:20.179Z
Learning: In packages/core/src/external/sftp/surescripts/client.ts, the standalone getPatientLoadFileName function intentionally omits the transmission ID from the filename, which differs from the class method getPatientLoadFileName. This difference in filename generation is expected behavior.
Learnt from: keshavsaharia
PR: metriport/metriport#3885
File: packages/core/src/external/sftp/surescripts/client.ts:1-134
Timestamp: 2025-05-28T19:23:20.179Z
Learning: In packages/core/src/external/sftp/surescripts/client.ts, the SurescriptsSftpClient constructor intentionally uses config.publicKey as the SFTP password field and config.username as the SFTP username field. This is the expected configuration for Surescripts SFTP authentication.
Learnt from: keshavsaharia
PR: metriport/metriport#3885
File: packages/core/src/external/surescripts/schema/load.ts:65-71
Timestamp: 2025-05-30T03:42:53.380Z
Learning: In Surescripts schema files like `packages/core/src/external/surescripts/schema/load.ts`, the `key` property in field definitions is only used for direct one-to-one field mappings. When multiple fields are derived from the same source property but with different transformations (like extracting date vs. time portions), they should not have `key` properties as they represent transformations rather than direct mappings.
Learnt from: thomasyopes
PR: metriport/metriport#3970
File: packages/api/src/external/ehr/athenahealth/command/write-back/medication.ts:17-17
Timestamp: 2025-06-06T16:45:31.832Z
Learning: The writeMedicationToChart function in packages/api/src/external/ehr/athenahealth/command/write-back/medication.ts returns a response that is not currently used by any consumers, so changes to its return type are not breaking changes in practice.
Learnt from: leite08
PR: metriport/metriport#3814
File: packages/api/src/routes/internal/medical/patient-consolidated.ts:141-174
Timestamp: 2025-05-20T21:26:26.804Z
Learning: The functionality introduced in packages/api/src/routes/internal/medical/patient-consolidated.ts is planned to be refactored in downstream PR #3857, including improvements to error handling and validation.
Learnt from: thomasyopes
PR: metriport/metriport#3608
File: packages/infra/lib/api-stack.ts:538-542
Timestamp: 2025-04-23T19:04:20.182Z
Learning: The `createAPIService` function in `packages/infra/lib/api-stack/api-service.ts` uses inline type definition in its parameter and does not use an `APIServiceProps` interface.
Learnt from: lucasdellabella
PR: metriport/metriport#3877
File: packages/infra/lib/hl7-notification-stack/mllp.ts:28-32
Timestamp: 2025-05-20T20:01:07.202Z
Learning: In packages/infra/lib/hl7-notification-stack/mllp.ts, the strict validation check that requires exactly one private subnet is intentional. It's designed to fail loudly and force code changes if subnet configurations change in the future, rather than silently adapting to potentially incompatible infrastructure changes.
Learnt from: keshavsaharia
PR: metriport/metriport#3885
File: packages/core/src/external/surescripts/client.ts:0-0
Timestamp: 2025-05-30T01:09:55.013Z
Learning: In packages/core/src/external/surescripts/client.ts, the Surescripts date formatting should use local time according to their documentation ("message-date-must-be-local"), which means buildDayjs() cannot be used since it defaults to UTC. The specific use case for transmission date formatting requires dayjs to be used directly to preserve local time behavior.
Learnt from: leite08
PR: metriport/metriport#3469
File: packages/utils/src/s3/list-objects.ts:12-13
Timestamp: 2025-03-14T01:14:58.991Z
Learning: In utility scripts under `./packages/utils/src/s3/`, empty string values like `const bucketName = ``; const filePrefix = ``;` are intentional placeholders meant to be filled in by developers before running the script, as documented in the TSDoc comments. These should not be flagged as issues or suggested to be replaced with environment variables.
Learnt from: keshavsaharia
PR: metriport/metriport#3887
File: packages/lambdas/src/surescripts-receive-flat-file-response.ts:11-35
Timestamp: 2025-05-22T16:36:54.189Z
Learning: The Surescripts Lambda handlers in packages/lambdas/src/ are stub implementations that will be replaced with more solid implementations later. These stubs don't require the same level of error handling and logging as production code.
Learnt from: thomasyopes
PR: metriport/metriport#4090
File: packages/core/src/command/conversion-fhir/conversion-fhir-cloud.ts:30-30
Timestamp: 2025-06-25T01:55:42.627Z
Learning: In packages/core/src/command/conversion-fhir/conversion-fhir-cloud.ts, the FHIR converter Lambda endpoint is controlled by the team and guaranteed to return valid JSON in the expected Bundle<Resource> format, so JSON.parse() error handling and type validation are not necessary for this specific endpoint.
🧬 Code Graph Analysis (1)
packages/infra/lib/surescripts/surescripts-stack.ts (1)
packages/core/src/external/term-server/index.ts (1)
  • termServerUrl (25-25)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check-pr / lint-build-test
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/infra/lib/surescripts/surescripts-stack.ts (3)

279-279: LGTM! Configuration properly propagated.

The termServerUrl is correctly added to the commonConfig object, ensuring it's available for all Lambda setups.


428-428: LGTM! Consistent parameter handling in setupLambda.

The implementation correctly:

  • Adds optional termServerUrl parameter to the method signature
  • Destructures it from props
  • Conditionally sets the TERM_SERVER_URL environment variable when provided

Also applies to: 443-443, 455-455


481-481: LGTM! Consistent parameter handling in setupLambdaAndQueue.

The implementation mirrors the pattern used in setupLambda, ensuring consistent behavior across both Lambda setup methods.

Also applies to: 494-494, 525-525

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

@keshavsaharia keshavsaharia marked this pull request as ready for review June 26, 2025 14:50
@keshavsaharia keshavsaharia added this pull request to the merge queue Jun 26, 2025
@keshavsaharia keshavsaharia mentioned this pull request Jun 26, 2025
3 tasks
Merged via the queue into develop with commit 6f8df2d Jun 26, 2025
14 checks passed
@keshavsaharia keshavsaharia deleted the eng-484-term-server-url branch June 26, 2025 14:59
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